| 1 |
use core::fmt::Write; |
| 2 |
|
| 3 |
use crate::back::hlsl::BackendResult; |
| 4 |
use crate::{RayQueryIntersection, TypeInner}; |
| 5 |
|
| 6 |
impl<W: Write> super::Writer<'_, W> { |
| 7 |
// constructs hlsl RayDesc from wgsl RayDesc |
| 8 |
pub(super) fn write_ray_desc_from_ray_desc_constructor_function( |
| 9 |
&mut self, |
| 10 |
module: &crate::Module, |
| 11 |
) -> BackendResult { |
| 12 |
write!(self.out, "RayDesc RayDescFromRayDesc_(")?; |
| 13 |
self.write_type(module, module.special_types.ray_desc.unwrap())?; |
| 14 |
writeln!(self.out, " arg0) {{")?; |
| 15 |
writeln!(self.out, " RayDesc ret = (RayDesc)0;")?; |
| 16 |
writeln!(self.out, " ret.Origin = arg0.origin;")?; |
| 17 |
writeln!(self.out, " ret.TMin = arg0.tmin;")?; |
| 18 |
writeln!(self.out, " ret.Direction = arg0.dir;")?; |
| 19 |
writeln!(self.out, " ret.TMax = arg0.tmax;")?; |
| 20 |
writeln!(self.out, " return ret;")?; |
| 21 |
writeln!(self.out, "}}")?; |
| 22 |
writeln!(self.out)?; |
| 23 |
Ok(()) |
| 24 |
} |
| 25 |
pub(super) fn write_committed_intersection_function( |
| 26 |
&mut self, |
| 27 |
module: &crate::Module, |
| 28 |
) -> BackendResult { |
| 29 |
self.write_type(module, module.special_types.ray_intersection.unwrap())?; |
| 30 |
write!(self.out, " GetCommittedIntersection(")?; |
| 31 |
self.write_value_type( |
| 32 |
module, |
| 33 |
&TypeInner::RayQuery { |
| 34 |
vertex_return: false, |
| 35 |
}, |
| 36 |
)?; |
| 37 |
writeln!(self.out, " rq) {{")?; |
| 38 |
write!(self.out, " ")?; |
| 39 |
self.write_type(module, module.special_types.ray_intersection.unwrap())?; |
| 40 |
write!(self.out, " ret = (")?; |
| 41 |
self.write_type(module, module.special_types.ray_intersection.unwrap())?; |
| 42 |
writeln!(self.out, ")0;")?; |
| 43 |
writeln!(self.out, " ret.kind = rq.CommittedStatus();")?; |
| 44 |
writeln!( |
| 45 |
self.out, |
| 46 |
" if( rq.CommittedStatus() == COMMITTED_NOTHING) {{}} else {{" |
| 47 |
)?; |
| 48 |
writeln!(self.out, " ret.t = rq.CommittedRayT();")?; |
| 49 |
writeln!( |
| 50 |
self.out, |
| 51 |
" ret.instance_custom_data = rq.CommittedInstanceID();" |
| 52 |
)?; |
| 53 |
writeln!( |
| 54 |
self.out, |
| 55 |
" ret.instance_index = rq.CommittedInstanceIndex();" |
| 56 |
)?; |
| 57 |
writeln!( |
| 58 |
self.out, |
| 59 |
" ret.sbt_record_offset = rq.CommittedInstanceContributionToHitGroupIndex();" |
| 60 |
)?; |
| 61 |
writeln!( |
| 62 |
self.out, |
| 63 |
" ret.geometry_index = rq.CommittedGeometryIndex();" |
| 64 |
)?; |
| 65 |
writeln!( |
| 66 |
self.out, |
| 67 |
" ret.primitive_index = rq.CommittedPrimitiveIndex();" |
| 68 |
)?; |
| 69 |
writeln!( |
| 70 |
self.out, |
| 71 |
" if( rq.CommittedStatus() == COMMITTED_TRIANGLE_HIT ) {{" |
| 72 |
)?; |
| 73 |
writeln!( |
| 74 |
self.out, |
| 75 |
" ret.barycentrics = rq.CommittedTriangleBarycentrics();" |
| 76 |
)?; |
| 77 |
writeln!( |
| 78 |
self.out, |
| 79 |
" ret.front_face = rq.CommittedTriangleFrontFace();" |
| 80 |
)?; |
| 81 |
writeln!(self.out, " }}")?; |
| 82 |
writeln!( |
| 83 |
self.out, |
| 84 |
" ret.object_to_world = rq.CommittedObjectToWorld4x3();" |
| 85 |
)?; |
| 86 |
writeln!( |
| 87 |
self.out, |
| 88 |
" ret.world_to_object = rq.CommittedWorldToObject4x3();" |
| 89 |
)?; |
| 90 |
writeln!(self.out, " }}")?; |
| 91 |
writeln!(self.out, " return ret;")?; |
| 92 |
writeln!(self.out, "}}")?; |
| 93 |
writeln!(self.out)?; |
| 94 |
Ok(()) |
| 95 |
} |
| 96 |
pub(super) fn write_candidate_intersection_function( |
| 97 |
&mut self, |
| 98 |
module: &crate::Module, |
| 99 |
) -> BackendResult { |
| 100 |
self.write_type(module, module.special_types.ray_intersection.unwrap())?; |
| 101 |
write!(self.out, " GetCandidateIntersection(")?; |
| 102 |
self.write_value_type( |
| 103 |
module, |
| 104 |
&TypeInner::RayQuery { |
| 105 |
vertex_return: false, |
| 106 |
}, |
| 107 |
)?; |
| 108 |
writeln!(self.out, " rq) {{")?; |
| 109 |
write!(self.out, " ")?; |
| 110 |
self.write_type(module, module.special_types.ray_intersection.unwrap())?; |
| 111 |
write!(self.out, " ret = (")?; |
| 112 |
self.write_type(module, module.special_types.ray_intersection.unwrap())?; |
| 113 |
writeln!(self.out, ")0;")?; |
| 114 |
writeln!(self.out, " CANDIDATE_TYPE kind = rq.CandidateType();")?; |
| 115 |
writeln!( |
| 116 |
self.out, |
| 117 |
" if (kind == CANDIDATE_NON_OPAQUE_TRIANGLE) {{" |
| 118 |
)?; |
| 119 |
writeln!( |
| 120 |
self.out, |
| 121 |
" ret.kind = {};", |
| 122 |
RayQueryIntersection::Triangle as u32 |
| 123 |
)?; |
| 124 |
writeln!(self.out, " ret.t = rq.CandidateTriangleRayT();")?; |
| 125 |
writeln!( |
| 126 |
self.out, |
| 127 |
" ret.barycentrics = rq.CandidateTriangleBarycentrics();" |
| 128 |
)?; |
| 129 |
writeln!( |
| 130 |
self.out, |
| 131 |
" ret.front_face = rq.CandidateTriangleFrontFace();" |
| 132 |
)?; |
| 133 |
writeln!(self.out, " }} else {{")?; |
| 134 |
writeln!( |
| 135 |
self.out, |
| 136 |
" ret.kind = {};", |
| 137 |
RayQueryIntersection::Aabb as u32 |
| 138 |
)?; |
| 139 |
writeln!(self.out, " }}")?; |
| 140 |
|
| 141 |
writeln!( |
| 142 |
self.out, |
| 143 |
" ret.instance_custom_data = rq.CandidateInstanceID();" |
| 144 |
)?; |
| 145 |
writeln!( |
| 146 |
self.out, |
| 147 |
" ret.instance_index = rq.CandidateInstanceIndex();" |
| 148 |
)?; |
| 149 |
writeln!( |
| 150 |
self.out, |
| 151 |
" ret.sbt_record_offset = rq.CandidateInstanceContributionToHitGroupIndex();" |
| 152 |
)?; |
| 153 |
writeln!( |
| 154 |
self.out, |
| 155 |
" ret.geometry_index = rq.CandidateGeometryIndex();" |
| 156 |
)?; |
| 157 |
writeln!( |
| 158 |
self.out, |
| 159 |
" ret.primitive_index = rq.CandidatePrimitiveIndex();" |
| 160 |
)?; |
| 161 |
writeln!( |
| 162 |
self.out, |
| 163 |
" ret.object_to_world = rq.CandidateObjectToWorld4x3();" |
| 164 |
)?; |
| 165 |
writeln!( |
| 166 |
self.out, |
| 167 |
" ret.world_to_object = rq.CandidateWorldToObject4x3();" |
| 168 |
)?; |
| 169 |
writeln!(self.out, " return ret;")?; |
| 170 |
writeln!(self.out, "}}")?; |
| 171 |
writeln!(self.out)?; |
| 172 |
Ok(()) |
| 173 |
} |
| 174 |
} |