Skip to content

Commit fc11779

Browse files
committed
check for f16 support
1 parent d01549c commit fc11779

File tree

1 file changed

+81
-6
lines changed

1 file changed

+81
-6
lines changed

src/App.jsx

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,48 @@ import ModelSelector, { AVAILABLE_MODELS } from "./components/ModelSelector";
88
import ModelSelectionModal from "./components/ModelSelectionModal";
99
import InlineProgress from "./components/InlineProgress";
1010

11-
const IS_WEBGPU_AVAILABLE = !!navigator.gpu;
11+
// Enhanced WebGPU compatibility check
12+
async function isWebGPUok() {
13+
if (!("gpu" in navigator)) {
14+
return { isSupported: false, error: 'WebGPU is NOT supported on this browser.' };
15+
}
16+
17+
const adapter = await navigator.gpu.requestAdapter();
18+
if (!adapter) {
19+
return { isSupported: false, error: 'WebGPU Adapter not found.' };
20+
}
21+
22+
const device = await adapter.requestDevice();
23+
if (!device) {
24+
return { isSupported: false, error: 'WebGPU Device not available.' };
25+
}
26+
27+
if (!adapter.features.has('shader-f16')) {
28+
return { isSupported: false, error: 'WebGPU "shader-f16" feature is NOT supported on this device.' };
29+
}
30+
31+
// Minimal Compute Shader WGSL code for test
32+
const shaderCode = `
33+
@compute @workgroup_size(1)
34+
fn main() {
35+
// simple no-op compute shader
36+
}
37+
`;
38+
39+
try {
40+
const shaderModule = device.createShaderModule({code: shaderCode});
41+
const info = await shaderModule.getCompilationInfo();
42+
if (info.messages.some(msg => msg.type === 'error')) {
43+
return { isSupported: false, error: 'ShaderModule compilation errors: ' + JSON.stringify(info.messages) };
44+
}
45+
46+
console.log('ShaderModule compiled successfully. WebGPU is working.');
47+
return { isSupported: true, error: null };
48+
} catch (err) {
49+
return { isSupported: false, error: 'ShaderModule creation failed: ' + JSON.stringify(err) };
50+
}
51+
}
52+
1253
const STICKY_SCROLL_THRESHOLD = 120;
1354
const EXAMPLES = [
1455
"Suggest strategies to stay focused while studying.",
@@ -68,6 +109,9 @@ function App() {
68109
const [showModelSelectionModal, setShowModelSelectionModal] = useState(false);
69110
const [hasInitialized, setHasInitialized] = useState(false);
70111

112+
// WebGPU compatibility
113+
const [webGPUStatus, setWebGPUStatus] = useState(null); // null = checking, true = ok, string = error message
114+
71115
// Inputs and outputs
72116
const [input, setInput] = useState("");
73117
const [messages, setMessages] = useState([]);
@@ -92,6 +136,25 @@ function App() {
92136
checkMobile();
93137
}, []);
94138

139+
useEffect(() => {
140+
const checkWebGPU = async () => {
141+
try {
142+
const { isSupported, error } = await isWebGPUok();
143+
setWebGPUStatus({
144+
isSupported,
145+
error: isSupported ? null : error
146+
});
147+
} catch (err) {
148+
setWebGPUStatus({
149+
isSupported: false,
150+
error: err.message || "Failed to check WebGPU compatibility"
151+
});
152+
}
153+
};
154+
155+
checkWebGPU();
156+
}, []);
157+
95158
function onEnter(message) {
96159
// Prevent queueing multiple messages
97160
if (status === "loading" && queuedMessage) {
@@ -407,7 +470,7 @@ function App() {
407470
);
408471
}
409472

410-
return IS_WEBGPU_AVAILABLE ? (
473+
return webGPUStatus?.isSupported ? (
411474
<div className="flex flex-col h-screen mx-auto items justify-end text-gray-800 dark:text-gray-200 bg-white dark:bg-gray-900">
412475
{/* New Chat button and Model selector - top left */}
413476
<div className="absolute top-4 left-4 z-10 flex flex-col gap-2">
@@ -580,10 +643,22 @@ function App() {
580643
</p>
581644
</div>
582645
) : (
583-
<div className="fixed w-screen h-screen bg-black z-10 bg-opacity-[92%] text-white text-2xl font-semibold flex justify-center items-center text-center">
584-
WebGPU is not supported
585-
<br />
586-
by this browser :&#40;
646+
<div className="fixed w-screen h-screen bg-black z-10 bg-opacity-[92%] text-white text-2xl font-semibold flex justify-center items-center text-center px-8">
647+
<div className="max-w-2xl">
648+
<div className="mb-4">
649+
WebGPU {webGPUStatus === null ? "Checking..." : "Not Compatible"}
650+
</div>
651+
{webGPUStatus?.error && (
652+
<div className="text-lg font-normal text-gray-300 mb-4">
653+
{webGPUStatus.error}
654+
</div>
655+
)}
656+
<div className="text-base font-normal text-gray-400">
657+
This application requires WebGPU support for AI model processing.
658+
<br />
659+
Please use a modern browser like Chrome, Firefox, or Edge.
660+
</div>
661+
</div>
587662
</div>
588663
);
589664
}

0 commit comments

Comments
 (0)