use concinnity_core::platform::Platform;
use concinnity_core::render::error::{RenderError, RenderResult};
use concinnity_shader::HlslTarget;
#[cfg(any(backend_vk, backend_dx))]
pub(crate) const COMPILER_TAG: &str = "hlsl";
pub(crate) fn toolchain_id() -> &'static str {
concinnity_shader::compiler_id()
}
pub(crate) fn compile(
file: &str,
entry: &str,
source: &str,
target: HlslTarget,
) -> RenderResult<Vec<u8>> {
let work = crate::shader::compiler_work::dir().map_err(RenderError::Other)?;
concinnity_shader::compile(&job(file, entry, source, target), work.path())
.map_err(RenderError::ShaderCompile)
}
pub(crate) fn cooked(
platform: Platform,
file: &str,
entry: &str,
source: &str,
) -> RenderResult<Vec<u8>> {
let work = crate::shader::compiler_work::dir().map_err(RenderError::Other)?;
let target = HlslTarget::cooked(platform);
let compiled =
concinnity_shader::compile_with_warnings(&job(file, entry, source, target), work.path())
.map_err(RenderError::ShaderCompile)?;
if let Some(warnings) = compiled.warnings {
tracing::warn!("world shader {file}: compiling '{entry}':\n{warnings}");
}
Ok(compiled.artifact)
}
fn job<'a>(
file: &'a str,
entry: &'a str,
source: &'a str,
target: HlslTarget,
) -> concinnity_shader::HlslJob<'a> {
concinnity_shader::HlslJob {
source,
file_name: file,
entry,
target,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_toolchain_id_names_the_compiler() {
assert!(toolchain_id().starts_with("dxc"), "{}", toolchain_id());
}
}