Skip to content

Commit 31a2257

Browse files
committed
Add an option to force use of wasi server if desktop server is used.
1 parent 64f373a commit 31a2257

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
### Added
11+
12+
- User can request the wasi server instead of the desktop server.
13+
1014
## [1.2.0] - 2025-10-04
1115

1216
### Changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@
266266
"description": "Override configuration with a path to a specific configuration file.",
267267
"type": "string",
268268
"default": ""
269+
},
270+
"shader-validator.useWasiServer": {
271+
"description": "Use the wasi server instead of the native server. Only working for platform where DXC is available.",
272+
"type": "boolean",
273+
"default": false
269274
}
270275
}
271276
},

src/client.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,10 @@ export class ServerVersion {
107107
this.path = ServerVersion.getPlatformBinaryUri(extensionUri, null, this.platform);
108108
this.cwd = ServerVersion.getPlatformBinaryDirectoryPath(extensionUri, null, this.platform);
109109
}
110-
}
111-
update() {
112-
113110
}
114111
private static getUserServerPathAndVersion(platform: ServerPlatform) : [string, string] | null {
115-
if (isRunningOnWeb()) {
116-
return null;
112+
if (platform === ServerPlatform.wasi) {
113+
return null; // Bundled wasi version
117114
} else {
118115
// Check configuration.
119116
let serverPath = vscode.workspace.getConfiguration("shader-validator").get<string>("serverPath");
@@ -201,10 +198,14 @@ export class ServerVersion {
201198
return vscode.Uri.joinPath(ServerVersion.getPlatformBinaryDirectoryPath(extensionUri, serverPath, platform), ServerVersion.getPlatformBinaryName(serverPath, platform));
202199
}
203200
static getServerPlatform() : ServerPlatform {
204-
if (isRunningOnWeb()) {
201+
let useWasiServer = vscode.workspace.getConfiguration("shader-validator").get<boolean>("useWasiServer")!;
202+
if (isRunningOnWeb() || useWasiServer) {
205203
return ServerPlatform.wasi;
206204
} else {
207205
// Dxc only built for linux x64 & windows x64. Fallback to WASI for every other situations.
206+
// TODO: ARM DLL available aswell, need to bundle them, along with correct version of server.
207+
// Should have an extension version per platform.
208+
// Could have a setting for user provided DLL path aswell, but useless if server does not match the platform.
208209
switch (process.platform) {
209210
case "win32":
210211
return (process.arch === 'x64') ? ServerPlatform.windows : ServerPlatform.wasi;
@@ -280,7 +281,7 @@ export class ShaderLanguageClient {
280281
this.statusChangedCallback = statusChangedCallback;
281282
}
282283

283-
async start(context: vscode.ExtensionContext): Promise<ServerStatus> {
284+
async start(context: vscode.ExtensionContext, updateServerUsed: boolean): Promise<ServerStatus> {
284285
if (this.serverStatus === ServerStatus.running) {
285286
return ServerStatus.running;
286287
}
@@ -296,20 +297,25 @@ export class ShaderLanguageClient {
296297
this.channel = null;
297298
break;
298299
}
299-
this.serverVersion.update();
300+
if (updateServerUsed) {
301+
this.updateServerVersion(context.extensionUri);
302+
}
300303
this.client = await this.createLanguageClient(context);
301304
this.serverStatus = this.client !== null ? ServerStatus.running : ServerStatus.error;
302305
return this.serverStatus;
303306
}
304307
async restart(context: vscode.ExtensionContext) {
305308
await this.stop();
306-
await this.start(context);
309+
await this.start(context, true);
307310
}
308311
async stop() {
309312
await this.client?.stop(100).catch(_ => {});
310313
this.dispose();
311314
this.serverStatus = ServerStatus.stopped;
312315
}
316+
updateServerVersion(extensionUri: vscode.Uri) {
317+
this.serverVersion = new ServerVersion(extensionUri);
318+
}
313319
updateStatus(status: ServerStatus) {
314320
this.serverStatus = status;
315321
this.statusChangedCallback(status);

src/extension.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function activate(context: vscode.ExtensionContext)
5252
// Create language client
5353
const server = new ShaderLanguageClient(context);
5454
context.subscriptions.push(server);
55-
const serverStatus = await server.start(context);
55+
const serverStatus = await server.start(context, false);
5656

5757
// Create sidebar
5858
sidebar = new ShaderVariantTreeDataProvider(context, server);
@@ -67,8 +67,8 @@ export async function activate(context: vscode.ExtensionContext)
6767
//client.sendRequest()
6868
vscode.window.showInformationMessage("Cannot validate file manually for now");
6969
}));
70-
context.subscriptions.push(vscode.commands.registerCommand("shader-validator.startServer", async () => {
71-
await server.start(context);
70+
context.subscriptions.push(vscode.commands.registerCommand("shader-validator.startServer", async (updateServerUsed: boolean) => {
71+
await server.start(context, updateServerUsed);
7272
statusBar.updateStatusBar();
7373
sidebar.onServerStart();
7474
}));
@@ -150,6 +150,7 @@ export async function activate(context: vscode.ExtensionContext)
150150
"shader-validator.hlsl.enabled",
151151
"shader-validator.glsl.enabled",
152152
"shader-validator.wgsl.enabled",
153+
"shader-validator.useWasiServer",
153154
];
154155
let requiresRestart = false;
155156
for (let configuration of configurationRequiringAServerRestart) {

src/view/shaderStatusBar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export class ShaderStatusBar {
5252
case ServerStatus.stopped:
5353
this.statusBar.color = new vscode.ThemeColor("statusBarItem.warningForeground");
5454
this.statusBar.backgroundColor = new vscode.ThemeColor("statusBarItem.warningBackground");
55-
this.statusBar.command = "shader-validator.startServer";
55+
this.statusBar.command = "shader-validator.startServer true";
5656
this.statusBar.text = "$(play-circle) shader-validator";
5757
statusString = `Server stopped.`;
58-
statusCommand = `[$(debug-start) Start Server](command:shader-validator.startServer "Start the server")`;
58+
statusCommand = `[$(debug-start) Start Server](command:shader-validator.startServer?%22true%22 "Start the server")`;
5959
break;
6060
default:
6161
break;

0 commit comments

Comments
 (0)