Repository navigation
Align testing API with wgsl-test and add reflection - #7
Merged
Merged
Conversation
Test helpers repeated the compiler settings in their own arguments, and Python tests repeated the shader root and dependencies that the fixtures already know. run_test, run_test_cpu, and the new run_compute now take a Compiler, so the wesl_compiler fixture supplies the modules, filenames, root directory, and dependencies. The native bindings read the same Compiler and add the wgsl_test package themselves. A root can also be a file path relative to the root directory, as in wesl-js testCompute. run_test compiles on each call, as expectWesl does, and replaces prepare_test. The constants argument fills the virtual constants:: module, as the constants argument of wesl-js link() does, and replaces constant_modules. A str value is a WGSL expression, so a parametrized pytest case can send a vector or an array into one WESL test. The wesl_constants fixture fills the same module, as in wgsl-test. The runner sets no pipeline override values, so an override that a test reads needs a default. The examples move the override logic into public functions that take the value as a parameter, and their tests pass values from constants::. A test can declare @buffer scratch storage, as in wgsl-test. The runner fills it with zeros and binds it after the result buffer. run_compute follows testCompute: it fills @buffer variables from NumPy values and returns each read_write buffer in the shape of its WGSL type. NumPy is now part of the testing extra. Automatic layouts bind only the resources that the test reaches, so one wesl_resources fixture can serve every test in a directory. The new wesl.reflect module reads buffer layouts, structure dtypes, and workgroup sizes from WESL declarations, so Python code does not repeat binding numbers and byte sizes. Its names follow wesl-reflect. A size that depends on an override gives None, because its value is unknown until pipeline creation. The assertion package adds exact i32 and integer vector comparisons, and the tolerance assertions fail on NaN. A failure reports the WGSL type of the compared values. A wgpu error shows each declaration as module::name in place of its mangled name. Compiler.from_project and the wesl_dependencies fixture load the path dependencies of wesl.toml, and Compiler.compile takes a module path. An unresolved module error names the dependencies or the missing root directory. Collected WESL tests no longer get the gpu marker. Use -m 'not wesl' to deselect them.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Test helpers repeated the compiler settings in their own arguments, and Python tests repeated the shader root and dependencies that the fixtures already know. run_test, run_test_cpu, and the new run_compute now take a Compiler, so the wesl_compiler fixture supplies the modules, filenames, root directory, and dependencies. The native bindings read the same Compiler and add the wgsl_test package themselves. A root can also be a file path relative to the root directory, as in wesl-js testCompute. run_test compiles on each call, as expectWesl does, and replaces prepare_test.
The constants argument fills the virtual constants:: module, as the constants argument of wesl-js link() does, and replaces constant_modules. A str value is a WGSL expression, so a parametrized pytest case can send a vector or an array into one WESL test. The wesl_constants fixture fills the same module, as in wgsl-test. The runner sets no pipeline override values, so an override that a test reads needs a default. The examples move the override logic into public functions that take the value as a parameter, and their tests pass values from constants::.
A test can declare
@bufferscratch storage, as in wgsl-test. The runner fills it with zeros and binds it after the result buffer. run_compute follows testCompute: it fills@buffervariables from NumPy values and returns each read_write buffer in the shape of its WGSL type. NumPy is now part of the testing extra. Automatic layouts bind only the resources that the test reaches, so one wesl_resources fixture can serve every test in a directory.The new wesl.reflect module reads buffer layouts, structure dtypes, and workgroup sizes from WESL declarations, so Python code does not repeat binding numbers and byte sizes. Its names follow wesl-reflect. A size that depends on an override gives None, because its value is unknown until pipeline creation.
The assertion package adds exact i32 and integer vector comparisons, and the tolerance assertions fail on NaN. A failure reports the WGSL type of the compared values. A wgpu error shows each declaration as module::name in place of its mangled name.
Compiler.from_project and the wesl_dependencies fixture load the path dependencies of wesl.toml, and Compiler.compile takes a module path. An unresolved module error names the dependencies or the missing root directory. Collected WESL tests no longer get the gpu marker. Use -m 'not wesl' to deselect them.