@@ -2,7 +2,7 @@ use wgpu::util::DeviceExt;
22use wgpu_test:: { gpu_test, GpuTestConfiguration , TestParameters , TestingContext } ;
33
44pub fn all_tests ( vec : & mut Vec < wgpu_test:: GpuTestInitializer > ) {
5- vec. push ( DRAW ) ;
5+ vec. push ( BARYCENTRIC ) ;
66}
77
88//
@@ -26,36 +26,26 @@ pub fn all_tests(vec: &mut Vec<wgpu_test::GpuTestInitializer>) {
2626//
2727// The fragment shader outputs color based on builtin(barycentric):
2828//
29- // return vec4<f32>(bary, 1.0);
29+ // return vec4<f32>(bary * 1.1 - 0.05 , 1.0);
3030//
3131
3232#[ gpu_test]
33- static DRAW : GpuTestConfiguration = GpuTestConfiguration :: new ( )
33+ static BARYCENTRIC : GpuTestConfiguration = GpuTestConfiguration :: new ( )
3434 . parameters (
3535 TestParameters :: default ( )
3636 . test_features_limits ( )
3737 . features ( wgpu:: Features :: SHADER_BARYCENTRICS ) ,
3838 )
39- . run_async ( |ctx| async move {
40- //
41- // +-----+-----+
42- // |blue |white|
43- // +-----+-----+
44- // | red |green|
45- // +-----+-----+
46- //
47- let expected = [
48- 0 , 0 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 0 , 0 , 255 , 0 , 255 , 0 , 255 ,
49- ] ;
50- draw ( ctx, & expected) . await ;
51- } ) ;
39+ . run_async ( barycentric) ;
5240
53- async fn draw ( ctx : TestingContext , expected : & [ u8 ] ) {
41+ async fn barycentric ( ctx : TestingContext ) {
5442 let shader = ctx
5543 . device
5644 . create_shader_module ( wgpu:: include_wgsl!( "barycentric.wgsl" ) ) ;
5745
58- let two_triangles_xy: [ f32 ; 6 ] = [ -0.5 , -0.5 , 0.5 , -0.5 , -0.5 , 0.5 ] ;
46+ let n = -0.505 ;
47+ let p = 0.51 ;
48+ let two_triangles_xy: [ f32 ; 6 ] = [ n, n, p, n, n, p] ;
5949 let vertex_buffer = ctx
6050 . device
6151 . create_buffer_init ( & wgpu:: util:: BufferInitDescriptor {
@@ -157,5 +147,18 @@ async fn draw(ctx: TestingContext, expected: &[u8]) {
157147 }
158148 readback_buffer. copy_from ( & ctx. device , & mut encoder, & color_texture) ;
159149 ctx. queue . submit ( Some ( encoder. finish ( ) ) ) ;
160- readback_buffer. assert_buffer_contents ( & ctx, expected) . await ;
150+
151+ //
152+ // +-----+-----+
153+ // |blue |white|
154+ // +-----+-----+
155+ // | red |green|
156+ // +-----+-----+
157+ //
158+ let expected = [
159+ 0 , 0 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 0 , 0 , 255 , 0 , 255 , 0 , 255 ,
160+ ] ;
161+ readback_buffer
162+ . assert_buffer_contents ( & ctx, & expected)
163+ . await ;
161164}
0 commit comments