Macro vulkanology::gen_simple_test_shader [] [src]

macro_rules! gen_simple_test_shader {
    (
        group_prefix: $group_prefix:ident,
        shader_name: $shader_name:ident,
        segments: [ $( $segment:expr ),* ]
    ) => { ... };
}

A simple macro for generating the build code which concatenates the correct test shader segments.

  • $group_prefix the prefix of the directory where tests for a particular UUT are located.
  • $shader_name the name of the shader test (should be a unique name). An identifier is expected here. After calling this macro this identifier will be bound to a &str, which is the path to concatenated shader file.
  • $segment a list of shader segments to include between the header and the main.

The directory structure for a single shader test function should look like the following:

  • build.rs: The build script which calls this macro and then compiles the concatenated shader.
  • tests/something.rs: A regular rust integration test with #[test] functions. The test functions should set up the test data, call the shader, and verify the result.
  • tests/shaders/<$shader_name>_header.comp: The test shader header. Contains extension pragmas layout definitions and all constants required for the shader segment under test to run. Additionally the following extension must be enabled to be able to compile segmented shaders with #line pragmas:

#extension GL_GOOGLE_cpp_style_line_directive : enable * tests/shaders/<$shader_name>_main.comp: The test shader main. Calls the tested function and writes its result to the provided result buffer. * <$segment>: Some segments which the test shader includes and tests.

The GLSL files are then concatenated into a complete shader: target/test_shaders/<$shader_name>.comp

Afterwards, the concatenated compute shader can either be directly passed to the Vulkan API as GLSL code, or compiled into a Rust interface module by the vulkano_shaders crate. vulkano_shaders provides a method called build_glsl_shaders which should be used in the build script, right after concatenating the shader fragments. The generated module would be located in: <OUT_DIR>/shaders/target/test_shaders/<$shader_name>.comp

Example

#[macro_use]
extern crate vulkanology;
use std::path::Path;

fn main() {
    // The path to the normal shader segments.
    // In this example it's the same folder as the test shader segments.
    let random_src_segment = Path::new("tests/shaders/random/random_segment.comp");

    // Path to tests for the random segment.
    let random_test_segments = Path::new("random");

    // Test for `next_u64()`.
    gen_simple_test_shader!{
        group_prefix: random_test_segments,
        shader_name: test_random_next_u64,
        segments: [random_src_segment]
    }

    // `test_random_next_u64` is now set to the `Path` to the concatenated file.
}