#![allow(dead_code)]
pub const TEMP: u32 = 0;
pub const INPUT: u32 = 1;
pub const CONST: u32 = 2;
pub const ADDR: u32 = 3;
pub const TEXTURE: u32 = 3;
pub const RASTOUT: u32 = 4;
pub const ATTROUT: u32 = 5;
pub const OUTPUT: u32 = 6;
pub const CONSTINT: u32 = 7;
pub const COLOROUT: u32 = 8;
pub const DEPTHOUT: u32 = 9;
pub const SAMPLER: u32 = 10;
pub const CONSTBOOL: u32 = 14;
pub const LOOP: u32 = 15;
pub const MISC: u32 = 17;
pub const LABEL: u32 = 18;
pub const PREDICATE: u32 = 19;
pub fn reg(kind: u32, n: u32) -> u32 {
0x8000_0000 | ((kind & 7) << 28) | ((kind & 0x18) << 8) | n
}
pub fn dst(kind: u32, n: u32, mask: u32) -> u32 {
reg(kind, n) | (mask << 16)
}
pub fn src(kind: u32, n: u32, swizzle: u32, modifier: u32) -> u32 {
reg(kind, n) | (swizzle << 16) | (modifier << 24)
}
pub fn op(code: u32, operands: &[u32]) -> Vec<u32> {
[vec![code | ((operands.len() as u32) << 24)], operands.to_vec()].concat()
}
pub fn op1(code: u32, operands: &[u32]) -> Vec<u32> {
[vec![code], operands.to_vec()].concat()
}
pub fn program(version: u32, body: &[Vec<u32>]) -> Vec<u8> {
std::iter::once(version)
.chain(body.iter().flatten().copied())
.chain([0xffff])
.flat_map(u32::to_le_bytes)
.collect()
}
pub fn refusal(bytes: &[u8]) -> (usize, String) {
let e = d3d9_reader::read(bytes).expect_err("a refusal");
(e.word, e.detail)
}