use super::{BC7, BIND_SCENE, DEFORMATION, MATERIAL, Module, PACKED_VERTEX, SCENE_SOURCE, SRGB};
pub(crate) static SCENE_RAYS: Module = Module {
name: "scene_rays",
source: include_str!("scene_rays.wgsl"),
deps: &[
&MATERIAL,
&SCENE_SOURCE,
&SRGB,
&PACKED_VERTEX,
&BIND_SCENE,
&BC7,
&DEFORMATION,
],
};
pub(crate) static SCENE_RAYS_PREDICATE: Module = Module {
name: "scene_rays_predicate",
source: include_str!("scene_rays_predicate.wgsl"),
deps: &[&SCENE_RAYS],
};
pub(crate) static SCENE_RAYS_WALK: Module = Module {
name: "scene_rays_walk",
source: include_str!("scene_rays_walk.wgsl"),
deps: &[&SCENE_RAYS_PREDICATE],
};
pub(crate) static SCENE_RAYS_PORTABLE: Module = Module {
name: "scene_rays_portable",
source: include_str!("scene_rays_portable.wgsl"),
deps: &[&SCENE_RAYS_WALK],
};
pub(crate) static SCENE_RAYS_HARDWARE: Module = Module {
name: "scene_rays_hardware",
source: include_str!("scene_rays_hardware.wgsl"),
deps: &[&SCENE_RAYS_WALK],
};
pub(crate) static SCENE_RAYS_QUERY_OPAQUE: Module = Module {
name: "scene_rays_query_opaque",
source: include_str!("scene_rays_query_opaque.wgsl"),
deps: &[&SCENE_RAYS_HARDWARE],
};
pub(crate) static SCENE_RAYS_QUERY_CANDIDATES: Module = Module {
name: "scene_rays_query_candidates",
source: include_str!("scene_rays_query_candidates.wgsl"),
deps: &[&SCENE_RAYS_HARDWARE],
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) enum RayQueryForm {
Baseline,
Candidates,
}
pub(crate) const LOWERED_FORM: RayQueryForm = RayQueryForm::Baseline;
pub(crate) const METAL_FORM: RayQueryForm = RayQueryForm::Candidates;
impl RayQueryForm {
pub fn lowered(backend: wgpu::Backend) -> bool {
matches!(
backend,
wgpu::Backend::Vulkan | wgpu::Backend::Dx12 | wgpu::Backend::Metal
)
}
pub fn of_backend(backend: wgpu::Backend) -> Self {
let recorded = match backend {
wgpu::Backend::Metal => METAL_FORM,
_ => LOWERED_FORM,
};
Self::gated(backend, recorded)
}
fn gated(backend: wgpu::Backend, form: Self) -> Self {
if Self::lowered(backend) {
form
} else {
Self::Baseline
}
}
}
pub(crate) fn ray_trace_root(form: Option<RayQueryForm>) -> &'static Module {
match form {
None => &SCENE_RAYS_PORTABLE,
Some(RayQueryForm::Baseline) => &SCENE_RAYS_QUERY_OPAQUE,
Some(RayQueryForm::Candidates) => &SCENE_RAYS_QUERY_CANDIDATES,
}
}
#[cfg(test)]
mod form_tests {
use super::RayQueryForm;
use wasm_bindgen_test::wasm_bindgen_test;
#[wasm_bindgen_test(unsupported = test)]
fn each_backend_runs_its_recorded_form() {
use RayQueryForm::{Baseline, Candidates};
use wgpu::Backend::{BrowserWebGpu, Dx12, Gl, Metal, Noop, Vulkan};
for (backend, form) in [
(Vulkan, Baseline),
(Dx12, Baseline),
(Metal, Candidates),
(Gl, Baseline),
(BrowserWebGpu, Baseline),
(Noop, Baseline),
] {
assert_eq!(RayQueryForm::of_backend(backend), form, "{backend:?}");
}
for backend in [Gl, BrowserWebGpu, Noop] {
assert_eq!(
RayQueryForm::gated(backend, Candidates),
Baseline,
"{backend:?}"
);
}
}
}