|
1 |
| -use std::iter; |
| 1 | +use std::{iter, mem}; |
2 | 2 |
|
3 | 3 | use crate::ray_tracing::AsBuildContext;
|
4 | 4 | use wgpu::util::{BufferInitDescriptor, DeviceExt};
|
@@ -604,3 +604,204 @@ fn only_tlas_vertex_return(ctx: TestingContext) {
|
604 | 604 | None,
|
605 | 605 | );
|
606 | 606 | }
|
| 607 | + |
| 608 | +#[gpu_test] |
| 609 | +static EXTRA_FORMAT_BUILD: GpuTestConfiguration = GpuTestConfiguration::new() |
| 610 | + .parameters( |
| 611 | + TestParameters::default() |
| 612 | + .test_features_limits() |
| 613 | + .features( |
| 614 | + wgpu::Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE |
| 615 | + | wgpu::Features::EXTENDED_ACCELERATION_STRUCTURE_VERTEX_FORMATS, |
| 616 | + ) |
| 617 | + // https://github.com/gfx-rs/wgpu/issues/6727 |
| 618 | + .skip(FailureCase::backend_adapter(wgpu::Backends::VULKAN, "AMD")), |
| 619 | + ) |
| 620 | + .run_sync(extra_format_build); |
| 621 | + |
| 622 | +fn extra_format_build(ctx: TestingContext) { |
| 623 | + let vertices = ctx.device.create_buffer_init(&BufferInitDescriptor { |
| 624 | + label: None, |
| 625 | + contents: &[0; mem::size_of::<[[i16; 3]; 3]>()], |
| 626 | + usage: BufferUsages::BLAS_INPUT, |
| 627 | + }); |
| 628 | + |
| 629 | + let blas_size = BlasTriangleGeometrySizeDescriptor { |
| 630 | + // The fourth component is ignored, and it allows us to have a smaller stride. |
| 631 | + vertex_format: VertexFormat::Snorm16x4, |
| 632 | + vertex_count: 3, |
| 633 | + index_format: None, |
| 634 | + index_count: None, |
| 635 | + flags: wgpu::AccelerationStructureGeometryFlags::empty(), |
| 636 | + }; |
| 637 | + |
| 638 | + let blas = ctx.device.create_blas( |
| 639 | + &CreateBlasDescriptor { |
| 640 | + label: Some("BLAS"), |
| 641 | + flags: wgpu::AccelerationStructureFlags::PREFER_FAST_TRACE, |
| 642 | + update_mode: AccelerationStructureUpdateMode::Build, |
| 643 | + }, |
| 644 | + BlasGeometrySizeDescriptors::Triangles { |
| 645 | + descriptors: vec![blas_size.clone()], |
| 646 | + }, |
| 647 | + ); |
| 648 | + |
| 649 | + let mut command_encoder = ctx |
| 650 | + .device |
| 651 | + .create_command_encoder(&CommandEncoderDescriptor { |
| 652 | + label: Some("BLAS_1"), |
| 653 | + }); |
| 654 | + command_encoder.build_acceleration_structures( |
| 655 | + &[BlasBuildEntry { |
| 656 | + blas: &blas, |
| 657 | + geometry: BlasGeometries::TriangleGeometries(vec![BlasTriangleGeometry { |
| 658 | + size: &blas_size, |
| 659 | + vertex_buffer: &vertices, |
| 660 | + first_vertex: 0, |
| 661 | + vertex_stride: mem::size_of::<[i16; 3]>() as BufferAddress, |
| 662 | + index_buffer: None, |
| 663 | + first_index: None, |
| 664 | + transform_buffer: None, |
| 665 | + transform_buffer_offset: None, |
| 666 | + }]), |
| 667 | + }], |
| 668 | + &[], |
| 669 | + ); |
| 670 | + ctx.queue.submit([command_encoder.finish()]); |
| 671 | +} |
| 672 | + |
| 673 | +#[gpu_test] |
| 674 | +static MISALIGNED_BUILD: GpuTestConfiguration = GpuTestConfiguration::new() |
| 675 | + .parameters( |
| 676 | + TestParameters::default() |
| 677 | + .test_features_limits() |
| 678 | + .features(wgpu::Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE) |
| 679 | + // https://github.com/gfx-rs/wgpu/issues/6727 |
| 680 | + .skip(FailureCase::backend_adapter(wgpu::Backends::VULKAN, "AMD")), |
| 681 | + ) |
| 682 | + .run_sync(misaligned_build); |
| 683 | + |
| 684 | +fn misaligned_build(ctx: TestingContext) { |
| 685 | + let vertices = ctx.device.create_buffer_init(&BufferInitDescriptor { |
| 686 | + label: None, |
| 687 | + contents: &[0; mem::size_of::<[[i16; 3]; 3]>()], |
| 688 | + usage: BufferUsages::BLAS_INPUT, |
| 689 | + }); |
| 690 | + |
| 691 | + let blas_size = BlasTriangleGeometrySizeDescriptor { |
| 692 | + // The fourth component is ignored, and it allows us to have a smaller stride. |
| 693 | + vertex_format: VertexFormat::Float32x3, |
| 694 | + vertex_count: 3, |
| 695 | + index_format: None, |
| 696 | + index_count: None, |
| 697 | + flags: wgpu::AccelerationStructureGeometryFlags::empty(), |
| 698 | + }; |
| 699 | + |
| 700 | + let blas = ctx.device.create_blas( |
| 701 | + &CreateBlasDescriptor { |
| 702 | + label: Some("BLAS"), |
| 703 | + flags: wgpu::AccelerationStructureFlags::PREFER_FAST_TRACE, |
| 704 | + update_mode: AccelerationStructureUpdateMode::Build, |
| 705 | + }, |
| 706 | + BlasGeometrySizeDescriptors::Triangles { |
| 707 | + descriptors: vec![blas_size.clone()], |
| 708 | + }, |
| 709 | + ); |
| 710 | + |
| 711 | + let mut command_encoder = ctx |
| 712 | + .device |
| 713 | + .create_command_encoder(&CommandEncoderDescriptor { |
| 714 | + label: Some("BLAS_1"), |
| 715 | + }); |
| 716 | + fail( |
| 717 | + &ctx.device, |
| 718 | + || { |
| 719 | + command_encoder.build_acceleration_structures( |
| 720 | + &[BlasBuildEntry { |
| 721 | + blas: &blas, |
| 722 | + geometry: BlasGeometries::TriangleGeometries(vec![BlasTriangleGeometry { |
| 723 | + size: &blas_size, |
| 724 | + vertex_buffer: &vertices, |
| 725 | + first_vertex: 0, |
| 726 | + // Not aligned to four bytes like it should be |
| 727 | + vertex_stride: 13, |
| 728 | + index_buffer: None, |
| 729 | + first_index: None, |
| 730 | + transform_buffer: None, |
| 731 | + transform_buffer_offset: None, |
| 732 | + }]), |
| 733 | + }], |
| 734 | + &[], |
| 735 | + ) |
| 736 | + }, |
| 737 | + None, |
| 738 | + ); |
| 739 | +} |
| 740 | + |
| 741 | +#[gpu_test] |
| 742 | +static TOO_SMALL_STRIDE_BUILD: GpuTestConfiguration = GpuTestConfiguration::new() |
| 743 | + .parameters( |
| 744 | + TestParameters::default() |
| 745 | + .test_features_limits() |
| 746 | + .features(wgpu::Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE) |
| 747 | + // https://github.com/gfx-rs/wgpu/issues/6727 |
| 748 | + .skip(FailureCase::backend_adapter(wgpu::Backends::VULKAN, "AMD")), |
| 749 | + ) |
| 750 | + .run_sync(too_small_stride_build); |
| 751 | + |
| 752 | +fn too_small_stride_build(ctx: TestingContext) { |
| 753 | + let vertices = ctx.device.create_buffer_init(&BufferInitDescriptor { |
| 754 | + label: None, |
| 755 | + contents: &[0; mem::size_of::<[[i16; 3]; 3]>()], |
| 756 | + usage: BufferUsages::BLAS_INPUT, |
| 757 | + }); |
| 758 | + |
| 759 | + let blas_size = BlasTriangleGeometrySizeDescriptor { |
| 760 | + // The fourth component is ignored, and it allows us to have a smaller stride. |
| 761 | + vertex_format: VertexFormat::Float32x3, |
| 762 | + vertex_count: 3, |
| 763 | + index_format: None, |
| 764 | + index_count: None, |
| 765 | + flags: wgpu::AccelerationStructureGeometryFlags::empty(), |
| 766 | + }; |
| 767 | + |
| 768 | + let blas = ctx.device.create_blas( |
| 769 | + &CreateBlasDescriptor { |
| 770 | + label: Some("BLAS"), |
| 771 | + flags: wgpu::AccelerationStructureFlags::PREFER_FAST_TRACE, |
| 772 | + update_mode: AccelerationStructureUpdateMode::Build, |
| 773 | + }, |
| 774 | + BlasGeometrySizeDescriptors::Triangles { |
| 775 | + descriptors: vec![blas_size.clone()], |
| 776 | + }, |
| 777 | + ); |
| 778 | + |
| 779 | + let mut command_encoder = ctx |
| 780 | + .device |
| 781 | + .create_command_encoder(&CommandEncoderDescriptor { |
| 782 | + label: Some("BLAS_1"), |
| 783 | + }); |
| 784 | + fail( |
| 785 | + &ctx.device, |
| 786 | + || { |
| 787 | + command_encoder.build_acceleration_structures( |
| 788 | + &[BlasBuildEntry { |
| 789 | + blas: &blas, |
| 790 | + geometry: BlasGeometries::TriangleGeometries(vec![BlasTriangleGeometry { |
| 791 | + size: &blas_size, |
| 792 | + vertex_buffer: &vertices, |
| 793 | + first_vertex: 0, |
| 794 | + // Aligned to four bytes but too small |
| 795 | + vertex_stride: 8, |
| 796 | + index_buffer: None, |
| 797 | + first_index: None, |
| 798 | + transform_buffer: None, |
| 799 | + transform_buffer_offset: None, |
| 800 | + }]), |
| 801 | + }], |
| 802 | + &[], |
| 803 | + ) |
| 804 | + }, |
| 805 | + None, |
| 806 | + ); |
| 807 | +} |
0 commit comments