blob: 93c0e864a43b72b17c335a658266bfc9075e95b0 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="resources/shaderProgram-utilities-webgpu.js"></script>
<script>
function test() {
let suite = InspectorTest.createAsyncSuite("Canvas.updateShader.WebGPU");
function test({name, programType, shaderType, source, shouldThrow}) {
suite.addTestCase({
name,
async test() {
let shaderProgram = InspectorTest.ShaderProgram.programForType(programType);
if (!shaderProgram)
throw "Missing shader program";
let originalSource = await CanvasAgent.requestShaderSource(shaderProgram.identifier, shaderType);
if (shouldThrow) {
await InspectorTest.expectException(async () => {
await CanvasAgent.updateShader(shaderProgram.identifier, shaderType, source);
});
} else
await CanvasAgent.updateShader(shaderProgram.identifier, shaderType, source);
let newSource = await CanvasAgent.requestShaderSource(shaderProgram.identifier, shaderType);
InspectorTest.expectNotShallowEqual(originalSource, newSource, "Source should have changed.");
}
});
}
test({
name: "Canvas.updateShader.WebGPU.Compute.Valid",
programType: WI.ShaderProgram.ProgramType.Compute,
shaderType: WI.ShaderProgram.ShaderType.Compute,
source: `// CHANGED COMPUTE
[numthreads(2, 1, 1)]
compute void computeShader(device float[] buffer : register(u0), float3 threadID : SV_DispatchThreadID) {
buffer[uint(threadID.x)] = buffer[uint(threadID.x)] * 2.0;
}
`,
});
test({
name: "Canvas.updateShader.WebGPU.Compute.Invalid",
programType: WI.ShaderProgram.ProgramType.Compute,
shaderType: WI.ShaderProgram.ShaderType.Compute,
source: "INVALID",
shouldThrow: true,
});
test({
name: "Canvas.updateShader.WebGPU.Vertex.Valid",
programType: WI.ShaderProgram.ProgramType.Render,
shaderType: WI.ShaderProgram.ShaderType.Vertex,
source: `// CHANGED VERTEX
vertex float4 vertexShader(float4 position : attribute(0), float i : attribute(1)) : SV_Position {
return position;
}
fragment float4 fragmentShader(float4 position : SV_Position) : SV_Target 0 {
return position;
}
`,
});
test({
name: "Canvas.updateShader.WebGPU.Vertex.Invalid",
programType: WI.ShaderProgram.ProgramType.Render,
shaderType: WI.ShaderProgram.ShaderType.Vertex,
source: "INVALID",
shouldThrow: true,
});
test({
name: "Canvas.updateShader.WebGPU.Fragment.Valid",
programType: WI.ShaderProgram.ProgramType.Render,
shaderType: WI.ShaderProgram.ShaderType.Fragment,
source: `// CHANGED FRAGMENT
vertex float4 vertexShader(float4 position : attribute(0), float i : attribute(1)) : SV_Position {
return position;
}
fragment float4 fragmentShader(float4 position : SV_Position) : SV_Target 0 {
return position;
}
`,
});
test({
name: "Canvas.updateShader.WebGPU.Fragment.Invalid",
programType: WI.ShaderProgram.ProgramType.Render,
shaderType: WI.ShaderProgram.ShaderType.Fragment,
source: "INVALID",
shouldThrow: true,
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="load()">
<p>WebGPU tests for Canvas.updateShader command.</p>
</body>
</html>