physis/
schd.rs

1// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4use std::io::Cursor;
5
6use crate::ByteSpan;
7use binrw::BinRead;
8use binrw::binread;
9
10#[binread]
11#[derive(Debug, Clone, Copy)]
12#[repr(C)]
13pub enum ShaderStage {
14    #[br(magic = 0u8)]
15    Vertex,
16    #[br(magic = 1u8)]
17    Pixel,
18}
19
20#[binread]
21#[derive(Debug)]
22#[brw(little)]
23#[allow(dead_code)]
24struct SchdHeader {
25    magic: i32, // TODO: what magic?
26
27    #[br(count = 3)]
28    #[bw(pad_size_to = 3)]
29    #[bw(map = |x : &String | x.as_bytes())]
30    #[br(map = | x: Vec<u8> | String::from_utf8(x).unwrap().trim_matches(char::from(0)).to_string())]
31    version: String,
32
33    stage: ShaderStage,
34
35    dxc_magic: u32, // TODO: WHAT MAGIC??
36
37    file_length: i32,
38    shader_offset: u32,
39    parameter_offset: u32,
40}
41
42#[derive(Debug)]
43pub struct Schd {}
44
45impl Schd {
46    /// Reads an existing ULD file
47    pub fn from_existing(buffer: ByteSpan) -> Option<Self> {
48        let mut cursor = Cursor::new(buffer);
49        SchdHeader::read(&mut cursor).ok()?;
50
51        Some(Schd {})
52    }
53}