Skip to content

Commit 2e9f080

Browse files
authored
Merge pull request #59 from csyonghe/main
Improve error messaging when webgpu is unavailable.
2 parents 3fb0fa4 + bc12db5 commit 2e9f080

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ class SlangCompiler
484484

485485
// Also read the shader work-group size.
486486
const entryPointReflection = linkedProgram.getLayout(0).findEntryPointByName(entryPointName);
487-
var threadGroupSize = entryPointReflection.getComputeThreadGroupSize();
487+
var threadGroupSize = entryPointReflection ? entryPointReflection.getComputeThreadGroupSize() :
488+
{ x: 1, y: 1, z: 1 };
488489

489490
if (outCode == "")
490491
{

try-slang.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,31 @@ var onRun = () => {
631631
});
632632
}
633633

634+
function appendOutput(editor, textLine) {
635+
editor.setValue(editor.getValue() + textLine + "\n");
636+
}
637+
634638
function compileOrRun() {
635639
const userSource = monacoEditor.getValue();
636640
const shaderType = checkShaderType(userSource);
641+
637642
if (shaderType == SlangCompiler.NON_RUNNABLE_SHADER) {
638643
onCompile();
639644
}
640645
else {
641-
onRun();
646+
if (device == null) {
647+
onCompile().then(() => {
648+
if (diagnosticsArea.getValue() == "")
649+
appendOutput(diagnosticsArea, `The shader compiled successfully,` +
650+
`but it cannot run because your browser does not support WebGPU.\n` +
651+
`WebGPU is supported in Chrome, Edge, Firefox Nightly or Safari Technology Preview. ` +
652+
`On iOS, WebGPU support requires Safari 16.4 or later and must be enabled in settings. ` +
653+
`Please check your browser version and enable WebGPU if possible.`);
654+
});
655+
}
656+
else {
657+
onRun();
658+
}
642659
}
643660
}
644661

@@ -730,6 +747,7 @@ function loadEditor(readOnlyMode = false, containerId, preloadCode) {
730747
readOnly: readOnlyMode,
731748
lineNumbers: readOnlyMode ? "off" : "on",
732749
automaticLayout: true,
750+
wordWrap: containerId == "diagnostics" ? "on" : "off",
733751
"semanticHighlighting.enabled": true,
734752
renderValidationDecorations: "on",
735753
minimap: {
@@ -771,7 +789,7 @@ var Module = {
771789
const progressBar = document.getElementById('progress-bar');
772790
const compressedData = await fetchWithProgress('slang-wasm.wasm.gz', (loaded, total) => {
773791
const progress = (loaded / total) * 100;
774-
progressBar.style.width = `${progress}%`;
792+
progressBar.style.width = `${progress} % `;
775793
});
776794

777795
// Step 2: Decompress the gzip data
@@ -842,14 +860,12 @@ function runIfFullyInitialized() {
842860

843861
restoreSelectedTargetFromURL();
844862

845-
if (device) {
846-
if (restoreDemoSelectionFromURL()) { }
847-
else if (monacoEditor.getValue() == "") {
848-
loadDemo(defaultShaderURL);
849-
}
850-
else {
851-
compileOrRun();
852-
}
863+
if (restoreDemoSelectionFromURL()) { }
864+
else if (monacoEditor.getValue() == "") {
865+
loadDemo(defaultShaderURL);
866+
}
867+
else {
868+
compileOrRun();
853869
}
854870
}
855871
}

0 commit comments

Comments
 (0)