|
| 1 | +use wgpu_test::{ |
| 2 | + gpu_test, image::ReadbackBuffers, GpuTestConfiguration, GpuTestInitializer, TestParameters, |
| 3 | + TestingContext, |
| 4 | +}; |
| 5 | + |
| 6 | +pub fn all_tests(vec: &mut Vec<GpuTestInitializer>) { |
| 7 | + vec.push(DONT_CARE); |
| 8 | +} |
| 9 | + |
| 10 | +#[gpu_test] |
| 11 | +static DONT_CARE: GpuTestConfiguration = GpuTestConfiguration::new() |
| 12 | + .parameters(TestParameters::default()) |
| 13 | + .run_async(run_test); |
| 14 | + |
| 15 | +async fn run_test(ctx: TestingContext) { |
| 16 | + let shader_src = " |
| 17 | + const triangles = array<vec2f, 3>(vec2f(-1.0, -1.0), vec2f(3.0, -1.0), vec2f(-1.0, 3.0)); |
| 18 | +
|
| 19 | + @vertex |
| 20 | + fn vs_main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4f { |
| 21 | + return vec4f(triangles[vertex_index], 0.0, 1.0); |
| 22 | + } |
| 23 | +
|
| 24 | + @fragment |
| 25 | + fn fs_main() -> @location(0) vec4f { |
| 26 | + return vec4f(127.0 / 255.0); |
| 27 | + } |
| 28 | + "; |
| 29 | + |
| 30 | + let shader = ctx |
| 31 | + .device |
| 32 | + .create_shader_module(wgpu::ShaderModuleDescriptor { |
| 33 | + label: None, |
| 34 | + source: wgpu::ShaderSource::Wgsl(shader_src.into()), |
| 35 | + }); |
| 36 | + |
| 37 | + let pipeline_desc = wgpu::RenderPipelineDescriptor { |
| 38 | + label: None, |
| 39 | + layout: None, |
| 40 | + vertex: wgpu::VertexState { |
| 41 | + buffers: &[], |
| 42 | + module: &shader, |
| 43 | + entry_point: Some("vs_main"), |
| 44 | + compilation_options: Default::default(), |
| 45 | + }, |
| 46 | + primitive: wgpu::PrimitiveState::default(), |
| 47 | + depth_stencil: None, |
| 48 | + multisample: wgpu::MultisampleState::default(), |
| 49 | + fragment: Some(wgpu::FragmentState { |
| 50 | + module: &shader, |
| 51 | + entry_point: Some("fs_main"), |
| 52 | + compilation_options: Default::default(), |
| 53 | + targets: &[Some(wgpu::ColorTargetState { |
| 54 | + format: wgpu::TextureFormat::Rgba8Unorm, |
| 55 | + blend: None, |
| 56 | + write_mask: wgpu::ColorWrites::ALL, |
| 57 | + })], |
| 58 | + }), |
| 59 | + multiview_mask: None, |
| 60 | + cache: None, |
| 61 | + }; |
| 62 | + let pipeline = ctx.device.create_render_pipeline(&pipeline_desc); |
| 63 | + |
| 64 | + let out_texture = ctx.device.create_texture(&wgpu::TextureDescriptor { |
| 65 | + label: None, |
| 66 | + size: wgpu::Extent3d { |
| 67 | + width: 1, |
| 68 | + height: 1, |
| 69 | + depth_or_array_layers: 1, |
| 70 | + }, |
| 71 | + mip_level_count: 1, |
| 72 | + sample_count: 1, |
| 73 | + dimension: wgpu::TextureDimension::D2, |
| 74 | + format: wgpu::TextureFormat::Rgba8Unorm, |
| 75 | + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, |
| 76 | + view_formats: &[], |
| 77 | + }); |
| 78 | + |
| 79 | + let readbacks = ReadbackBuffers::new(&ctx.device, &out_texture); |
| 80 | + |
| 81 | + let mut encoder = ctx |
| 82 | + .device |
| 83 | + .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); |
| 84 | + |
| 85 | + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { |
| 86 | + label: None, |
| 87 | + color_attachments: &[Some(wgpu::RenderPassColorAttachment { |
| 88 | + view: &out_texture.create_view(&wgpu::TextureViewDescriptor::default()), |
| 89 | + depth_slice: None, |
| 90 | + resolve_target: None, |
| 91 | + ops: wgpu::Operations { |
| 92 | + load: wgpu::LoadOp::DontCare(unsafe { wgpu::LoadOpDontCare::enabled() }), |
| 93 | + store: wgpu::StoreOp::Store, |
| 94 | + }, |
| 95 | + })], |
| 96 | + depth_stencil_attachment: None, |
| 97 | + timestamp_writes: None, |
| 98 | + occlusion_query_set: None, |
| 99 | + multiview_mask: None, |
| 100 | + }); |
| 101 | + rpass.set_pipeline(&pipeline); |
| 102 | + rpass.draw(0..3, 0..1); |
| 103 | + |
| 104 | + drop(rpass); |
| 105 | + |
| 106 | + readbacks.copy_from(&ctx.device, &mut encoder, &out_texture); |
| 107 | + |
| 108 | + ctx.queue.submit([encoder.finish()]); |
| 109 | + |
| 110 | + // Assert that DONT_CARE load op was fully overridden by the draw. |
| 111 | + readbacks |
| 112 | + .assert_buffer_contents(&ctx, &[127, 127, 127, 127]) |
| 113 | + .await; |
| 114 | +} |
0 commit comments