pub struct PolygonAccelerationStructure { /* private fields */ }Implementations§
Source§impl PolygonAccelerationStructure
impl PolygonAccelerationStructure
Sourcepub fn new(device: &MetalDevice) -> Option<Self>
pub fn new(device: &MetalDevice) -> Option<Self>
Examples found in repository?
examples/04_ray_intersection.rs (line 59)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}pub fn polygon_type(&self) -> usize
Sourcepub fn set_polygon_type(&self, polygon_type: usize)
pub fn set_polygon_type(&self, polygon_type: usize)
Examples found in repository?
examples/04_ray_intersection.rs (line 60)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}pub fn vertex_stride(&self) -> usize
Sourcepub fn set_vertex_stride(&self, vertex_stride: usize)
pub fn set_vertex_stride(&self, vertex_stride: usize)
Examples found in repository?
examples/04_ray_intersection.rs (line 61)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}pub fn index_type(&self) -> u32
Sourcepub fn set_index_type(&self, index_type: u32)
pub fn set_index_type(&self, index_type: u32)
Examples found in repository?
examples/04_ray_intersection.rs (line 62)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}Sourcepub fn set_vertex_buffer(&self, buffer: Option<&MetalBuffer>)
pub fn set_vertex_buffer(&self, buffer: Option<&MetalBuffer>)
Examples found in repository?
examples/04_ray_intersection.rs (line 63)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}pub fn vertex_buffer_offset(&self) -> usize
pub fn set_vertex_buffer_offset(&self, offset: usize)
Sourcepub fn set_index_buffer(&self, buffer: Option<&MetalBuffer>)
pub fn set_index_buffer(&self, buffer: Option<&MetalBuffer>)
Examples found in repository?
examples/04_ray_intersection.rs (line 64)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}pub fn index_buffer_offset(&self) -> usize
pub fn set_index_buffer_offset(&self, offset: usize)
pub fn polygon_count(&self) -> usize
Sourcepub fn set_polygon_count(&self, count: usize)
pub fn set_polygon_count(&self, count: usize)
Examples found in repository?
examples/04_ray_intersection.rs (line 65)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}pub fn usage(&self) -> usize
pub fn set_usage(&self, usage: usize)
Sourcepub fn status(&self) -> usize
pub fn status(&self) -> usize
Examples found in repository?
examples/04_ray_intersection.rs (line 68)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}Sourcepub fn rebuild(&self)
pub fn rebuild(&self)
Examples found in repository?
examples/04_ray_intersection.rs (line 66)
41fn main() {
42 let device = MetalDevice::system_default().expect("no Metal device available");
43 let queue = device.new_command_queue().expect("command queue");
44
45 let vertices = [
46 [-1.0_f32, -1.0, 0.0, 0.0],
47 [1.0_f32, -1.0, 0.0, 0.0],
48 [0.0_f32, 1.0, 0.0, 0.0],
49 ];
50 let vertex_buffer = device
51 .new_buffer(
52 core::mem::size_of_val(&vertices),
53 resource_options::STORAGE_MODE_SHARED,
54 )
55 .expect("vertex buffer");
56 let _ = vertex_buffer.write_bytes(as_bytes(&vertices));
57
58 let acceleration_structure =
59 PolygonAccelerationStructure::new(&device).expect("polygon acceleration structure");
60 acceleration_structure.set_polygon_type(polygon_type::TRIANGLE);
61 acceleration_structure.set_vertex_stride(core::mem::size_of::<[f32; 4]>());
62 acceleration_structure.set_index_type(data_type::UINT32);
63 acceleration_structure.set_vertex_buffer(Some(&vertex_buffer));
64 acceleration_structure.set_index_buffer(None);
65 acceleration_structure.set_polygon_count(1);
66 acceleration_structure.rebuild();
67 assert_eq!(
68 acceleration_structure.status(),
69 acceleration_structure_status::BUILT,
70 "acceleration structure should build successfully"
71 );
72
73 let ray = PackedRayOriginDirection {
74 origin: PackedFloat3 {
75 x: 0.0,
76 y: 0.0,
77 z: 1.0,
78 },
79 direction: PackedFloat3 {
80 x: 0.0,
81 y: 0.0,
82 z: -1.0,
83 },
84 };
85 let miss = IntersectionDistancePrimitiveIndex {
86 distance: -1.0,
87 primitive_index: u32::MAX,
88 };
89
90 let ray_buffer = device
91 .new_buffer(
92 core::mem::size_of::<PackedRayOriginDirection>(),
93 resource_options::STORAGE_MODE_SHARED,
94 )
95 .expect("ray buffer");
96 let intersection_buffer = device
97 .new_buffer(
98 core::mem::size_of::<IntersectionDistancePrimitiveIndex>(),
99 resource_options::STORAGE_MODE_SHARED,
100 )
101 .expect("intersection buffer");
102 let _ = ray_buffer.write_bytes(as_bytes(&[ray]));
103 let _ = intersection_buffer.write_bytes(as_bytes(&[miss]));
104
105 let intersector = RayIntersector::new(&device).expect("ray intersector");
106 intersector.set_cull_mode(cull_mode::NONE);
107 intersector.set_ray_data_type(ray_data_type::PACKED_ORIGIN_DIRECTION);
108 intersector.set_intersection_data_type(intersection_data_type::DISTANCE_PRIMITIVE_INDEX);
109 assert!(
110 intersector.recommended_minimum_ray_batch_size(1) >= 1,
111 "recommended ray batch size should be positive"
112 );
113
114 let command_buffer = queue.new_command_buffer().expect("command buffer");
115 intersector.encode_intersection(
116 &command_buffer,
117 intersection_type::NEAREST,
118 &ray_buffer,
119 0,
120 &intersection_buffer,
121 0,
122 1,
123 &acceleration_structure,
124 );
125 command_buffer.commit();
126 command_buffer.wait_until_completed();
127
128 let intersection = read_struct::<IntersectionDistancePrimitiveIndex>(&intersection_buffer);
129 assert!(
130 (intersection.distance - 1.0).abs() < 1.0e-4,
131 "unexpected hit distance: {intersection:?}"
132 );
133 assert_eq!(
134 intersection.primitive_index, 0,
135 "expected to hit triangle 0"
136 );
137
138 let svgf = SVGF::new(&device).expect("svgf");
139 svgf.set_depth_weight(0.75);
140 svgf.set_normal_weight(64.0);
141 svgf.set_luminance_weight(2.5);
142 svgf.set_channel_count(3);
143 svgf.set_channel_count2(1);
144 assert!((svgf.depth_weight() - 0.75).abs() < f32::EPSILON);
145 assert!((svgf.normal_weight() - 64.0).abs() < f32::EPSILON);
146 assert!((svgf.luminance_weight() - 2.5).abs() < f32::EPSILON);
147 assert_eq!(svgf.channel_count(), 3);
148 assert_eq!(svgf.channel_count2(), 1);
149
150 println!(
151 "ray smoke passed: distance={:.3} primitive_index={} batch_size={}",
152 intersection.distance,
153 intersection.primitive_index,
154 intersector.recommended_minimum_ray_batch_size(1)
155 );
156}pub fn encode_refit(&self, command_buffer: &CommandBuffer)
Trait Implementations§
Source§impl Drop for PolygonAccelerationStructure
impl Drop for PolygonAccelerationStructure
impl Send for PolygonAccelerationStructure
impl Sync for PolygonAccelerationStructure
Auto Trait Implementations§
impl Freeze for PolygonAccelerationStructure
impl RefUnwindSafe for PolygonAccelerationStructure
impl Unpin for PolygonAccelerationStructure
impl UnsafeUnpin for PolygonAccelerationStructure
impl UnwindSafe for PolygonAccelerationStructure
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more