-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validation tests for statement behavior analysis #3506
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/webgpu/shader/validation/parse/statement_behavior.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
export const description = ` | ||
Test statement behavior analysis. | ||
|
||
Functions must have a behavior of {Return}, {Next}, or {Return, Next}. | ||
Functions with a return type must have a behavior of {Return}. | ||
|
||
Each statement in the function must be valid according to the table. | ||
`; | ||
|
||
import { makeTestGroup } from '../../../../common/framework/test_group.js'; | ||
import { keysOf } from '../../../../common/util/data_tables.js'; | ||
import { ShaderValidationTest } from '../shader_validation_test.js'; | ||
|
||
export const g = makeTestGroup(ShaderValidationTest); | ||
|
||
const kInvalidStatements = { | ||
break: `break`, | ||
break_if: `break if true`, | ||
continue: `continue`, | ||
loop1: `loop { }`, | ||
loop2: `loop { continuing { } }`, | ||
loop3: `loop { continue; continuing { } }`, | ||
loop4: `loop { continuing { break; } }`, | ||
loop5: `loop { continuing { continue; } }`, | ||
loop6: `loop { continuing { return; } }`, | ||
loop7: `loop { continue; break; }`, | ||
loop8: `loop { continuing { break if true; return; } }`, | ||
for1: `for (;;) { }`, | ||
for2: `for (var i = 0; ; i++) { }`, | ||
for3: `for (;; break) { }`, | ||
for4: `for (;; continue ) { }`, | ||
for5: `for (;; return ) { }`, | ||
for6: `for (;;) { continue; break; }`, | ||
// while loops always have break in their behaviors. | ||
switch1: `switch (1) { case 1 { } }`, | ||
sequence1: `return; loop { }`, | ||
compound1: `{ loop { } }`, | ||
}; | ||
|
||
g.test('invalid_statements') | ||
.desc('Test statements with invalid behaviors') | ||
.specURL('https://gpuweb.github.io/gpuweb/wgsl/#behaviors-rules') | ||
.params(u => u.combine('body', keysOf(kInvalidStatements))) | ||
.fn(t => { | ||
const body = kInvalidStatements[t.params.body]; | ||
const code = `fn foo() { | ||
${body}; | ||
}`; | ||
t.expectCompileResult(false, code); | ||
}); | ||
|
||
const kValidStatements = { | ||
empty: ``, | ||
const_assert: `const_assert true`, | ||
let: `let x = 1`, | ||
var1: `var x = 1`, | ||
var2: `var x : i32`, | ||
assign: `v = 1`, | ||
phony_assign: `_ = 1`, | ||
compound_assign: `v += 1`, | ||
return: `return`, | ||
discard: `discard`, | ||
function_call1: `bar()`, | ||
function_call2: `workgroupBarrier()`, | ||
|
||
if1: `if true { } else { }`, | ||
if2: `if true { }`, | ||
|
||
break1: `loop { break; }`, | ||
break2: `loop { if false { break; } }`, | ||
break_if: `loop { continuing { break if false; } }`, | ||
|
||
continue1: `loop { continue; continuing { break if true; } }`, | ||
|
||
loop1: `loop { break; }`, | ||
loop2: `loop { break; continuing { } }`, | ||
loop3: `loop { continue; continuing { break if true; } }`, | ||
loop4: `loop { break; continue; }`, | ||
|
||
for1: `for (; true; ) { }`, | ||
for2: `for (;;) { break; }`, | ||
for3: `for (;true;) { continue; }`, | ||
|
||
while1: `while true { }`, | ||
while2: `while true { continue; }`, | ||
while3: `while true { continue; break; }`, | ||
|
||
switch1: `switch 1 { default { } }`, | ||
swtich2: `switch 1 { case 1 { } default { } }`, | ||
switch3: `switch 1 { default { break; } }`, | ||
switch4: `switch 1 { default { } case 1 { break; } }`, | ||
|
||
sequence1: `return; let x = 1`, | ||
sequence2: `if true { } let x = 1`, | ||
sequence3: `switch 1 { default { break; return; } }`, | ||
|
||
compound1: `{ }`, | ||
compound2: `{ loop { break; } if true { return; } }`, | ||
}; | ||
|
||
g.test('valid_statements') | ||
.desc('Test statements with valid behaviors') | ||
.specURL('https://gpuweb.github.io/gpuweb/wgsl/#behaviors-rules') | ||
.params(u => u.combine('body', keysOf(kValidStatements))) | ||
.fn(t => { | ||
const body = kValidStatements[t.params.body]; | ||
const code = ` | ||
var<private> v : i32; | ||
fn bar() { } | ||
fn foo() { | ||
${body}; | ||
}`; | ||
t.expectCompileResult(true, code); | ||
}); | ||
|
||
const kInvalidFunctions = { | ||
next_for_type: `fn foo() -> bool { }`, | ||
next_return_for_type: `fn foo() -> bool { if true { return true; } }`, | ||
}; | ||
|
||
g.test('invalid_functions') | ||
.desc('Test functions with invalid behaviors') | ||
.specURL('https://gpuweb.github.io/gpuweb/wgsl/#behaviors-rules') | ||
.params(u => u.combine('function', keysOf(kInvalidFunctions))) | ||
.fn(t => { | ||
const func = kInvalidFunctions[t.params.function]; | ||
t.expectCompileResult(false, func); | ||
}); | ||
|
||
const kValidFunctions = { | ||
empty: `fn foo() { }`, | ||
next_return: `fn foo() { if true { return; } }`, | ||
no_final_return: `fn foo() -> bool { if true { return true; } else { return false; } }`, | ||
}; | ||
|
||
g.test('valid_functions') | ||
.desc('Test functions with valid behaviors') | ||
.specURL('https://gpuweb.github.io/gpuweb/wgsl/#behaviors-rules') | ||
.params(u => u.combine('function', keysOf(kValidFunctions))) | ||
.fn(t => { | ||
const func = kValidFunctions[t.params.function]; | ||
t.expectCompileResult(true, func); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is invalid because there's no default clause - was there something specific to the behavior analysis that it was supposed to be testing instead?