Skip to content

Commit

Permalink
Add support for SPV_KHR_ray_tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Mar 31, 2021
1 parent 9723e12 commit 5fe8d7a
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ syn = { version = "1", features = ["visit", "visit-mut"] }
# Normal dependencies.
bimap = "0.6"
indexmap = "1.6.0"
rspirv = { git = "https://github.com/gfx-rs/rspirv.git", rev = "ee1e913" }
rspirv = { git = "https://github.com/EmbarkStudios/rspirv.git", rev = "7c72c65" }
rustc-demangle = "0.1.18"
sanitize-filename = "0.3"
serde = { version = "1.0", features = ["derive"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,9 @@ fn trans_intrinsic_type<'tcx>(
}
Ok(SpirvType::Sampler.def(span, cx))
}
IntrinsicType::AccelerationStructureKhr => {
Ok(SpirvType::AccelerationStructureKhr.def(span, cx))
}
IntrinsicType::SampledImage => {
// see SpirvType::sizeof
if ty.size != Size::from_bytes(4) {
Expand Down
1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub enum IntrinsicType {
access_qualifier: Option<AccessQualifier>,
},
Sampler,
AccelerationStructureKhr,
SampledImage,
}

Expand Down
6 changes: 6 additions & 0 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
SpirvType::Image { .. } => self.fatal("cannot memset image"),
SpirvType::Sampler => self.fatal("cannot memset sampler"),
SpirvType::SampledImage { .. } => self.fatal("cannot memset sampled image"),
SpirvType::AccelerationStructureKhr => {
self.fatal("cannot memset acceleration structure")
}
}
}

Expand Down Expand Up @@ -288,6 +291,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
SpirvType::Image { .. } => self.fatal("cannot memset image"),
SpirvType::Sampler => self.fatal("cannot memset sampler"),
SpirvType::SampledImage { .. } => self.fatal("cannot memset sampled image"),
SpirvType::AccelerationStructureKhr => {
self.fatal("cannot memset acceleration structure")
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ impl<'tcx> CodegenCx<'tcx> {
.tcx
.sess
.fatal("Cannot create a constant sampled image value"),
SpirvType::AccelerationStructureKhr => self
.tcx
.sess
.fatal("Cannot create a constant acceleration structure"),
}
}
}
8 changes: 5 additions & 3 deletions crates/rustc_codegen_spirv/src/codegen_cx/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
SpirvType::Function { .. } => TypeKind::Function,
// HACK(eddyb) this is probably the closest `TypeKind` (which is still
// very much LLVM-specific, sadly) has to offer to "resource handle".
SpirvType::Image { .. } |
SpirvType::Sampler |
SpirvType::SampledImage { .. } => TypeKind::Token,
| SpirvType::Image { .. }
| SpirvType::Sampler
| SpirvType::SampledImage { .. }
| SpirvType::AccelerationStructureKhr
=> TypeKind::Token,
}
}
fn type_ptr_to(&self, ty: Self::Type) -> Self::Type {
Expand Down
16 changes: 12 additions & 4 deletions crates/rustc_codegen_spirv/src/spirv_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub enum SpirvType {
SampledImage {
image_type: Word,
},
AccelerationStructureKhr,
}

impl SpirvType {
Expand Down Expand Up @@ -247,6 +248,7 @@ impl SpirvType {
access_qualifier,
),
Self::Sampler => cx.emit_global().type_sampler(),
Self::AccelerationStructureKhr => cx.emit_global().type_acceleration_structure_khr(),
Self::SampledImage { image_type } => cx.emit_global().type_sampled_image(image_type),
};
cx.type_cache.def(result, self);
Expand Down Expand Up @@ -320,7 +322,8 @@ impl SpirvType {
Self::Void
| Self::Opaque { .. }
| Self::RuntimeArray { .. }
| Self::Function { .. } => return None,
| Self::Function { .. }
| Self::AccelerationStructureKhr => return None,

Self::Bool => Size::from_bytes(1),
Self::Integer(width, _) | Self::Float(width) => Size::from_bits(width),
Expand All @@ -340,9 +343,10 @@ impl SpirvType {
pub fn alignof<'tcx>(&self, cx: &CodegenCx<'tcx>) -> Align {
match *self {
// Types that have no concept of size or alignment.
Self::Void | Self::Opaque { .. } | Self::Function { .. } => {
Align::from_bytes(0).unwrap()
}
Self::Void
| Self::Opaque { .. }
| Self::Function { .. }
| Self::AccelerationStructureKhr => Align::from_bytes(0).unwrap(),

Self::Bool => Align::from_bytes(1).unwrap(),
Self::Integer(width, _) | Self::Float(width) => Align::from_bits(width as u64).unwrap(),
Expand Down Expand Up @@ -499,6 +503,9 @@ impl fmt::Debug for SpirvTypePrinter<'_, '_> {
.field("id", &self.id)
.field("image_type", &self.cx.debug_type(image_type))
.finish(),
SpirvType::AccelerationStructureKhr => {
f.debug_struct("AccelerationStructureKhr").finish()
}
};
{
let mut debug_stack = DEBUG_STACK.lock().unwrap();
Expand Down Expand Up @@ -654,6 +661,7 @@ impl SpirvTypePrinter<'_, '_> {
.debug_struct("SampledImage")
.field("image_type", &self.cx.debug_type(image_type))
.finish(),
SpirvType::AccelerationStructureKhr => f.write_str("AccelerationStructureKhr"),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_codegen_spirv/src/spirv_type_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,15 +727,15 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
| Op::ExecuteCallableKHR
| Op::ConvertUToAccelerationStructureKHR
| Op::IgnoreIntersectionKHR
| Op::TerminateRayKHR => reserved!(SPV_KHR_ray_tracing),
| Op::TerminateRayKHR => {}
// SPV_KHR_ray_query
Op::TypeRayQueryKHR
| Op::RayQueryInitializeKHR
| Op::RayQueryTerminateKHR
| Op::RayQueryGenerateIntersectionKHR
| Op::RayQueryConfirmIntersectionKHR
| Op::RayQueryProceedKHR
| Op::RayQueryGetIntersectionTypeKHR => reserved!(SPV_KHR_ray_query),
| Op::RayQueryGetIntersectionTypeKHR => {}
// SPV_AMD_shader_fragment_mask
Op::FragmentMaskFetchAMD | Op::FragmentFetchAMD => reserved!(SPV_AMD_shader_fragment_mask),
// SPV_KHR_shader_clock
Expand All @@ -748,7 +748,7 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
| Op::TerminateRayNV
| Op::TraceNV
| Op::TypeAccelerationStructureNV
| Op::ExecuteCallableNV => reserved!(SPV_NV_ray_tracing),
| Op::ExecuteCallableNV => {}
// SPV_NV_cooperative_matrix
Op::TypeCooperativeMatrixNV
| Op::CooperativeMatrixLoadNV
Expand Down
44 changes: 24 additions & 20 deletions crates/rustc_codegen_spirv/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,21 @@ const BUILTINS: &[(&str, BuiltIn)] = {
("bary_coord_no_persp_nv", BaryCoordNoPerspNV),
("frag_size_ext", FragSizeEXT),
("frag_invocation_count_ext", FragInvocationCountEXT),
("launch_id_nv", LaunchIdNV),
("launch_size_nv", LaunchSizeNV),
("world_ray_origin_nv", WorldRayOriginNV),
("world_ray_direction_nv", WorldRayDirectionNV),
("object_ray_origin_nv", ObjectRayOriginNV),
("object_ray_direction_nv", ObjectRayDirectionNV),
("ray_tmin_nv", RayTminNV),
("ray_tmax_nv", RayTmaxNV),
("instance_custom_index_nv", InstanceCustomIndexNV),
("object_to_world_nv", ObjectToWorldNV),
("world_to_object_nv", WorldToObjectNV),
("hit_t_nv", HitTNV),
("hit_kind_nv", HitKindNV),
("incoming_ray_flags_nv", IncomingRayFlagsNV),
("launch_id_khr", LaunchIdNV),
("launch_size_khr", LaunchSizeNV),
("instance_custom_index_khr", InstanceCustomIndexNV),
("ray_geometry_index_khr", RayGeometryIndexKHR),
("world_ray_origin_khr", WorldRayOriginNV),
("world_ray_direction_khr", WorldRayDirectionNV),
("object_ray_origin_khr", ObjectRayOriginNV),
("object_ray_direction_khr", ObjectRayDirectionNV),
("ray_tmin_khr", RayTminNV),
("ray_tmax_khr", RayTmaxNV),
("object_to_world_khr", ObjectToWorldNV),
("world_to_object_khr", WorldToObjectNV),
("hit_kind_khr", HitKindNV),
("incoming_ray_flags_khr", IncomingRayFlagsNV),
("hit_t_nv", HitTNV),
("warps_per_sm_nv", WarpsPerSMNV),
("sm_count_nv", SMCountNV),
("warp_id_nv", WarpIDNV),
Expand Down Expand Up @@ -198,12 +198,12 @@ const EXECUTION_MODELS: &[(&str, ExecutionModel)] = {
("kernel", Kernel),
("task_nv", TaskNV),
("mesh_nv", MeshNV),
("ray_generation_nv", RayGenerationNV),
("intersection_nv", IntersectionNV),
("any_hit_nv", AnyHitNV),
("closest_hit_nv", ClosestHitNV),
("miss_nv", MissNV),
("callable_nv", CallableNV),
("ray_generation_khr", RayGenerationNV),
("intersection_khr", IntersectionNV),
("any_hit_khr", AnyHitNV),
("closest_hit_khr", ClosestHitNV),
("miss_khr", MissNV),
("callable_khr", CallableNV),
]
};

Expand Down Expand Up @@ -334,6 +334,10 @@ impl Symbols {
"sampler",
SpirvAttribute::IntrinsicType(IntrinsicType::Sampler),
),
(
"acceleration_structure_khr",
SpirvAttribute::IntrinsicType(IntrinsicType::AccelerationStructureKhr),
),
("block", SpirvAttribute::Block),
("flat", SpirvAttribute::Flat),
("invariant", SpirvAttribute::Invariant),
Expand Down
2 changes: 2 additions & 0 deletions crates/spirv-std/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use crate::{scalar::Scalar, vector::Vector};
mod arithmetic;
mod derivative;
mod primitive;
mod ray_tracing;

pub use arithmetic::*;
pub use derivative::*;
pub use primitive::*;
pub use ray_tracing::*;

/// Result is true if any component of `vector` is true, otherwise result is
/// false.
Expand Down
Loading

0 comments on commit 5fe8d7a

Please sign in to comment.