Browse Source

use better formatting

master
Alison Watson 2 years ago
parent
commit
02632f81d3
  1. 8
      rustfmt.toml
  2. 4
      source/framework/conf.rs
  3. 14
      source/framework/data/image.rs
  4. 20
      source/framework/data/model.rs
  5. 5
      source/framework/data/read.rs
  6. 14
      source/framework/data/text.rs
  7. 19
      source/framework/data/vfs.rs
  8. 40
      source/framework/defl.rs
  9. 4
      source/framework/hal/evt.rs
  10. 8
      source/framework/hal/win.rs
  11. 4
      source/framework/log.rs
  12. 18
      source/framework/log/color.rs
  13. 14
      source/framework/log/level.rs
  14. 5
      source/framework/log/standard.rs
  15. 24
      source/framework/render/buffer.rs
  16. 3
      source/framework/render/cmd.rs
  17. 8
      source/framework/render/conf.rs
  18. 6
      source/framework/render/descriptorpool.rs
  19. 15
      source/framework/render/device.rs
  20. 3
      source/framework/render/fence.rs
  21. 12
      source/framework/render/framebuffer.rs
  22. 33
      source/framework/render/image.rs
  23. 7
      source/framework/render/instance.rs
  24. 7
      source/framework/render/model.rs
  25. 6
      source/framework/render/pipeline.rs
  26. 4
      source/framework/render/properties.rs
  27. 3
      source/framework/render/queue.rs
  28. 3
      source/framework/render/renderpass.rs
  29. 3
      source/framework/render/sampler.rs
  30. 3
      source/framework/render/semaphore.rs
  31. 3
      source/framework/render/shader.rs
  32. 3
      source/framework/render/surface.rs
  33. 6
      source/framework/render/swapchain.rs
  34. 21
      source/framework/vire/compiler/function.rs
  35. 20
      source/framework/vire/compiler/types.rs
  36. 32
      source/framework/vire/parser.rs
  37. 149
      source/framework/vire/parser/tok.rs
  38. 28
      source/main_test/entry.rs
  39. 4
      source/main_test/main.rs

8
rustfmt.toml

@ -1,6 +1,14 @@
edition = "2018"
fn_args_layout = "Compressed"
force_explicit_abi = true
hard_tabs = true
match_arm_leading_pipes = "Always"
max_width = 79
merge_derives = true
newline_style = "Unix"
remove_nested_parens = true
reorder_imports = true
reorder_modules = true
tab_spaces = 3
use_field_init_shorthand = true
use_small_heuristics = "Max"

4
source/framework/conf.rs

@ -18,8 +18,8 @@ pub enum ErrConfLoad {
impl From<std::io::Error> for ErrConfLoad {
fn from(err: std::io::Error) -> Self {
match err.kind() {
std::io::ErrorKind::NotFound => Self::NoFile,
_ => Self::File(err),
| std::io::ErrorKind::NotFound => Self::NoFile,
| _ => Self::File(err),
}
}
}

14
source/framework/data/image.rs

@ -74,9 +74,9 @@ impl Image {
// make sure the encoding is OK
let alpha = match head[16] {
24 => false,
32 => true,
_ => return Err(ErrImageRead::Encoding),
| 24 => false,
| 32 => true,
| _ => return Err(ErrImageRead::Encoding),
};
let descr = head[17];
@ -204,8 +204,8 @@ where
fn next(&mut self) -> Option<Self::Item> {
match self {
Self::Not(it) => it.next(),
Self::Rev(it) => it.next_back(),
| Self::Not(it) => it.next(),
| Self::Rev(it) => it.next_back(),
}
}
}
@ -216,8 +216,8 @@ where
{
fn len(&self) -> usize {
match self {
Self::Not(it) => it.len(),
Self::Rev(it) => it.len(),
| Self::Not(it) => it.len(),
| Self::Rev(it) => it.len(),
}
}
}

20
source/framework/data/model.rs

@ -93,8 +93,8 @@ impl Iterator for VertexZipper {
self.wgt_v.next(),
self.clr_v.next(),
) {
(None, None, None, None, None, None) => None,
tuple => Some(tuple),
| (None, None, None, None, None, None) => None,
| tuple => Some(tuple),
}
}
}
@ -187,7 +187,7 @@ impl Model {
rd.seek(SeekFrom::Start(of))?;
match ty {
0 => {
| 0 => {
for pos in read::hunk(rd, 4 * 3 * num_vert)?.chunks(4 * 3) {
let x = read::f32le_32(pos, 0);
let y = read::f32le_32(pos, 4);
@ -195,14 +195,14 @@ impl Model {
pos_v.push(Vec3A::new(x, y, z));
}
}
1 => {
| 1 => {
for tex in read::hunk(rd, 4 * 2 * num_vert)?.chunks(4 * 2) {
let u = read::f32le_32(tex, 0);
let v = read::f32le_32(tex, 4);
tex_v.push(Vec3A::new(u, v, 0.0));
}
}
2 => {
| 2 => {
for nrm in read::hunk(rd, 4 * 3 * num_vert)?.chunks(4 * 3) {
let x = read::f32le_32(nrm, 0);
let y = read::f32le_32(nrm, 4);
@ -210,10 +210,10 @@ impl Model {
nrm_v.push(Vec3A::new(x, y, z));
}
}
3 => {
| 3 => {
// ignore tangents for now
}
4 => {
| 4 => {
for idx in read::hunk(rd, 4 * num_vert)?.chunks(4) {
let idx0 = f32::from(idx[0]);
let idx1 = f32::from(idx[1]);
@ -222,7 +222,7 @@ impl Model {
idx_v.push(Vec4::new(idx0, idx1, idx2, idx3));
}
}
5 => {
| 5 => {
for wgt in read::hunk(rd, 4 * num_vert)?.chunks(4) {
let wgt0 = f32::from(wgt[0]) / 255.0;
let wgt1 = f32::from(wgt[1]) / 255.0;
@ -231,7 +231,7 @@ impl Model {
wgt_v.push(Vec4::new(wgt0, wgt1, wgt2, wgt3));
}
}
6 => {
| 6 => {
for clr in read::hunk(rd, 4 * num_vert)?.chunks(4) {
let r = f32::from(clr[0]) / 255.0;
let g = f32::from(clr[1]) / 255.0;
@ -240,7 +240,7 @@ impl Model {
clr_v.push(Vec4::new(r, g, b, a));
}
}
_ => return Err(Err::UnknownType),
| _ => return Err(Err::UnknownType),
}
}

5
source/framework/data/read.rs

@ -25,10 +25,7 @@ pub fn f32le_32(b: &[u8], p: usize) -> f32 {
}
pub fn array<'a, 'b, T>(
f: impl Fn(&[u8], usize) -> T,
b: &'a [u8],
v: &'b mut [T],
step: usize,
f: impl Fn(&[u8], usize) -> T, b: &'a [u8], v: &'b mut [T], step: usize,
beg: usize,
) -> &'b [T] {
for (i, p) in (beg..beg + v.len() * step).step_by(step).enumerate() {

14
source/framework/data/text.rs

@ -25,16 +25,16 @@ impl Iterator for PosReader<'_> {
fn next(&mut self) -> Option<Self::Item> {
match self.itr.next() {
Some('\n') => {
| Some('\n') => {
self.pos.line += 1;
self.pos.colu = 0;
Some('\n')
}
Some(c) => {
| Some(c) => {
self.pos.colu += 1;
Some(c)
}
None => None,
| None => None,
}
}
}
@ -107,10 +107,10 @@ pub fn ellipsize_small_str(inp: &str) -> ([u8; 32], usize) {
pub const fn radix(c: char) -> u8 {
c as u8
- match c {
'a'..='z' => 0x61 - 10,
'A'..='Z' => 0x41 - 10,
'0'..='9' => 0x30,
_ => 0,
| 'a'..='z' => 0x61 - 10,
| 'A'..='Z' => 0x41 - 10,
| '0'..='9' => 0x30,
| _ => 0,
}
}

19
source/framework/data/vfs.rs

@ -2,8 +2,7 @@ use crate::{data::read, defl};
use smol_str::SmolStr;
use std::{
collections::HashMap,
fmt,
fs,
fmt, fs,
hash::Hasher,
io::{self, Read},
iter::FromIterator,
@ -60,8 +59,7 @@ fn path_to_local(top_path: &Path, path: &Path) -> SmolStr {
}
fn file_ref(
file_dat: &mut HashMap<u64, File>,
mut data: Vec<u8>,
file_dat: &mut HashMap<u64, File>, mut data: Vec<u8>,
) -> Result<u64, ErrArc> {
// un-gzip
if let Some(data_p) = defl::read_gzip(&data) {
@ -114,9 +112,7 @@ impl Arc {
pub fn read_dir(path: &Path) -> Result<Pin<Box<Self>>, ErrArc> {
fn recurse(
top_path: &Path,
cur_path: &Path,
file_dat: &mut HashMap<u64, File>,
top_path: &Path, cur_path: &Path, file_dat: &mut HashMap<u64, File>,
name_map: &mut HashMap<SmolStr, u64>,
) -> Result<(), ErrArc> {
for ent in fs::read_dir(cur_path)? {
@ -177,16 +173,16 @@ impl Arc {
}
match ftyp {
'g' | 'x' | 'A'..='Z' | '5' => {
| 'g' | 'x' | 'A'..='Z' | '5' => {
// skip extensions and directories entirely
}
'0' | '\0' | '7' => {
| '0' | '\0' | '7' => {
// file plus padding
let data = read::hunk(rd, size)?;
rd.read_exact(&mut junk[..512 - size % 512])?;
name_map.insert(name, file_ref(&mut file_dat, data)?);
}
_ => {
| _ => {
// some unsupported type
return Err(ErrArc::FileType(name));
}
@ -201,8 +197,7 @@ impl Arc {
}
fn finalize(
file_dat: HashMap<u64, File>,
name_map: HashMap<SmolStr, u64>,
file_dat: HashMap<u64, File>, name_map: HashMap<SmolStr, u64>,
) -> Result<Pin<Box<Self>>, ErrArc> {
// create a flat map of names
let mut refs_dat = Vec::with_capacity(name_map.len());

40
source/framework/defl.rs

@ -110,10 +110,10 @@ pub fn read_defl(b: &[u8], p: &mut usize) -> Result<Vec<u8>, Err> {
*p += 3;
match bstype {
0b10 => st_dynamic(b, p, &mut v)?,
0b01 => st_s_table(b, p, &mut v)?,
0b00 => st_literal(b, p, &mut v)?,
_ => return Err(Err::BlockType),
| 0b10 => st_dynamic(b, p, &mut v)?,
| 0b01 => st_s_table(b, p, &mut v)?,
| 0b00 => st_literal(b, p, &mut v)?,
| _ => return Err(Err::BlockType),
}
if bfinal == 1 {
@ -171,9 +171,9 @@ fn st_s_table(b: &[u8], p: &mut usize, v: &mut Vec<u8>) -> Result<(), Err> {
for (i, len) in len.iter_mut().enumerate() {
*len = match i {
144..=255 => 9,
256..=279 => 7,
_ => 8,
| 144..=255 => 9,
| 256..=279 => 7,
| _ => 8,
};
}
@ -208,10 +208,7 @@ fn next_alpha(alpha: &mut [u16], i: &mut usize, n: u16) -> Result<(), Err> {
}
fn read_alphabet(
b: &[u8],
p: &mut usize,
n: usize,
table: &HuffmanTable,
b: &[u8], p: &mut usize, n: usize, table: &HuffmanTable,
) -> Result<Vec<u16>, Err> {
let mut alpha = vec![0; n];
let mut i = 0;
@ -220,11 +217,11 @@ fn read_alphabet(
let ty = table.decode(b, p)?;
match ty {
0..=15 => {
| 0..=15 => {
// raw code
next_alpha(&mut alpha, &mut i, ty)?;
}
16 => {
| 16 => {
// copy previous code 3-6 times
let lst = *alpha.get(i - 1).ok_or(Err::BitsCode)?;
let len = u8::read_bits_le(b, *p, 2).ok_or(Err::BitsCode)? + 3;
@ -234,7 +231,7 @@ fn read_alphabet(
next_alpha(&mut alpha, &mut i, lst)?;
}
}
17 => {
| 17 => {
// repeat '0' 3-10 times
let len = u8::read_bits_le(b, *p, 3).ok_or(Err::Bits0)? + 3;
*p += 3;
@ -243,7 +240,7 @@ fn read_alphabet(
next_alpha(&mut alpha, &mut i, 0)?;
}
}
18 => {
| 18 => {
// repeat '0' 11-138 times
let len = u8::read_bits_le(b, *p, 7).ok_or(Err::Bits0)? + 11;
*p += 7;
@ -252,7 +249,7 @@ fn read_alphabet(
next_alpha(&mut alpha, &mut i, 0)?;
}
}
_ => {
| _ => {
return Err(Err::Symbol);
}
}
@ -262,10 +259,7 @@ fn read_alphabet(
}
fn output_tables(
b: &[u8],
p: &mut usize,
v: &mut Vec<u8>,
table_len: &HuffmanTable,
b: &[u8], p: &mut usize, v: &mut Vec<u8>, table_len: &HuffmanTable,
table_dst: &HuffmanTable,
) -> Result<(), Err> {
const LEN_BASE: [usize; 29] = [
@ -293,15 +287,15 @@ fn output_tables(
let ty = table_len.decode(b, p)?;
match ty.cmp(&256) {
Ordering::Less => {
| Ordering::Less => {
// direct byte
v.push(ty as u8);
}
Ordering::Equal => {
| Ordering::Equal => {
// finished
return Ok(());
}
Ordering::Greater => {
| Ordering::Greater => {
// <len, dst> pair
// decode the length (plus extra bits)

4
source/framework/hal/evt.rs

@ -23,8 +23,8 @@ impl Iterator for EventIterator {
fn read_in(evt: sdl::SDL_Event) -> Option<Event> {
let typ = unsafe { std::mem::transmute(evt.type_) };
match typ {
sdl::SDL_EventType::SDL_QUIT => Some(Event::Quit),
_ => None,
| sdl::SDL_EventType::SDL_QUIT => Some(Event::Quit),
| _ => None,
}
}

8
source/framework/hal/win.rs

@ -13,10 +13,7 @@ pub struct Window<'a> {
impl<'a> Window<'a> {
pub fn new(
_hal: &'a ctx::Context,
title: ffi::Nts,
w: i16,
h: i16,
_hal: &'a ctx::Context, title: ffi::Nts, w: i16, h: i16,
) -> Result<Self, Err> {
let handle = unsafe {
sdl::SDL_CreateWindow(
@ -66,8 +63,7 @@ impl<'a> Window<'a> {
}
pub fn vulkan_create_surface(
&self,
instance: &crate::render::Instance,
&self, instance: &crate::render::Instance,
) -> Result<vk::SurfaceKHR, Err> {
let mut surface = 0;
let res = unsafe {

4
source/framework/log.rs

@ -117,9 +117,7 @@ impl Log {
}
pub fn write_into(
&self,
args: std::fmt::Arguments,
record: Record,
&self, args: std::fmt::Arguments, record: Record,
out: &mut impl std::io::Write,
) -> std::io::Result<()> {
writeln!(

18
source/framework/log/color.rs

@ -7,21 +7,19 @@ pub struct Color;
impl Color {
fn write_level(
&self,
level: Level,
out: &mut impl WriteColor,
&self, level: Level, out: &mut impl WriteColor,
) -> std::io::Result<()> {
use termcolor::Color;
let (color, intense) = match level {
Level::Critical => (Color::Red, true),
Level::Error => (Color::Red, false),
Level::Warning => (Color::Yellow, true),
Level::Notice => (Color::Yellow, false),
Level::Info => (Color::Cyan, true),
Level::Debug => (Color::Cyan, false),
| Level::Critical => (Color::Red, true),
| Level::Error => (Color::Red, false),
| Level::Warning => (Color::Yellow, true),
| Level::Notice => (Color::Yellow, false),
| Level::Info => (Color::Cyan, true),
| Level::Debug => (Color::Cyan, false),
#[cfg(debug_assertions)]
Level::Trace => (Color::Magenta, true),
| Level::Trace => (Color::Magenta, true),
};
let mut spec = ColorSpec::new();

14
source/framework/log/level.rs

@ -33,14 +33,14 @@ impl Default for Level {
impl fmt::Display for Level {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Critical => f.write_str("Critical"),
Self::Error => f.write_str("Error"),
Self::Warning => f.write_str("Warning"),
Self::Notice => f.write_str("Notice"),
Self::Info => f.write_str("Info"),
Self::Debug => f.write_str("Debug"),
| Self::Critical => f.write_str("Critical"),
| Self::Error => f.write_str("Error"),
| Self::Warning => f.write_str("Warning"),
| Self::Notice => f.write_str("Notice"),
| Self::Info => f.write_str("Info"),
| Self::Debug => f.write_str("Debug"),
#[cfg(debug_assertions)]
Self::Trace => f.write_str("Trace"),
| Self::Trace => f.write_str("Trace"),
}
}
}

5
source/framework/log/standard.rs

@ -5,10 +5,7 @@ pub struct Std;
impl Std {
fn write_into(
&self,
args: std::fmt::Arguments,
record: Record,
log: &Log,
&self, args: std::fmt::Arguments, record: Record, log: &Log,
out: &mut impl Write,
) -> std::io::Result<()> {
write!(out, "[{:^8}]", record.level)?;

24
source/framework/render/buffer.rs

@ -15,9 +15,7 @@ pub struct Buffer {
}
unsafe fn create_buffer(
device: &Device,
size: vk::DeviceSize,
usage: vk::BufferUsageFlags,
device: &Device, size: vk::DeviceSize, usage: vk::BufferUsageFlags,
memory_flags: vk::MemoryPropertyFlags,
) -> Result<(vk::Buffer, vk::DeviceMemory), ErrAllocMem> {
let create_info = vk::BufferCreateInfo {
@ -48,8 +46,7 @@ impl GetDevice for Buffer {
impl Buffer {
/// Creates a vertex buffer.
pub fn create_vert(
cmd_pool: &CommandPool,
vertices: &[Vertex],
cmd_pool: &CommandPool, vertices: &[Vertex],
) -> Result<Rc<Self>, ErrAllocMem> {
let device = cmd_pool.get_device().clone();
let size = dev_size_of(vertices);
@ -73,8 +70,7 @@ impl Buffer {
/// Creates an index buffer.
pub fn create_indx(
cmd_pool: &CommandPool,
indices: &[u32],
cmd_pool: &CommandPool, indices: &[u32],
) -> Result<Rc<Self>, ErrAllocMem> {
let device = cmd_pool.get_device().clone();
let size = dev_size_of(indices);
@ -98,8 +94,7 @@ impl Buffer {
/// Creates an image buffer.
pub fn create_image(
device: Rc<Device>,
images: &[data::image::Image],
device: Rc<Device>, images: &[data::image::Image],
) -> Result<Rc<Self>, ErrAllocMem> {
let size =
images.iter().fold(0, |acc, img| acc + dev_size_of(img.data()));
@ -131,8 +126,7 @@ impl Buffer {
/// Creates a uniform buffer.
pub fn create_uniform(
device: Rc<Device>,
size: vk::DeviceSize,
device: Rc<Device>, size: vk::DeviceSize,
) -> Result<Rc<Self>, ErrAllocMem> {
let (handle, memory) = unsafe {
create_buffer(
@ -149,9 +143,7 @@ impl Buffer {
/// Copies the contents of `src` to `self` using a transient pool.
unsafe fn copy_buffer(
&self,
src: &Self,
cmd_pool: &CommandPool,
&self, src: &Self, cmd_pool: &CommandPool,
) -> Result<(), vk::Result> {
cmd_pool.with_transient_buffer(|cbuf| {
let copy =
@ -165,9 +157,7 @@ impl Buffer {
/// Transfers `data` from the client to the server.
pub fn xfer_data<T>(
&self,
cmd_pool: &CommandPool,
data: &[T],
&self, cmd_pool: &CommandPool, data: &[T],
) -> Result<(), ErrAllocMem> {
let size = dev_size_of(data);

3
source/framework/render/cmd.rs

@ -92,8 +92,7 @@ impl CommandPool {
impl CommandBuffers {
pub fn allocate(
pool: Rc<CommandPool>,
amount: usize,
pool: Rc<CommandPool>, amount: usize,
) -> Result<Rc<Self>, vk::Result> {
let create_info = vk::CommandBufferAllocateInfo {
command_pool: **pool,

8
source/framework/render/conf.rs

@ -22,10 +22,10 @@ pub struct Conf {
impl From<PresentMode> for vk::PresentModeKHR {
fn from(mode: PresentMode) -> Self {
match mode {
PresentMode::Fifo => Self::FIFO,
PresentMode::FifoRelaxed => Self::FIFO_RELAXED,
PresentMode::Immediate => Self::IMMEDIATE,
PresentMode::Mailbox => Self::MAILBOX,
| PresentMode::Fifo => Self::FIFO,
| PresentMode::FifoRelaxed => Self::FIFO_RELAXED,
| PresentMode::Immediate => Self::IMMEDIATE,
| PresentMode::Mailbox => Self::MAILBOX,
}
}
}

6
source/framework/render/descriptorpool.rs

@ -22,10 +22,8 @@ impl GetDevice for DescriptorPool {
impl DescriptorPool {
pub fn create(
layout: Rc<DescriptorSetLayout>,
buffers: Vec<(Rc<Buffer>, Rc<Buffer>)>,
image_view: Rc<ImageView>,
sampler: Rc<Sampler>,
layout: Rc<DescriptorSetLayout>, buffers: Vec<(Rc<Buffer>, Rc<Buffer>)>,
image_view: Rc<ImageView>, sampler: Rc<Sampler>,
) -> Result<Rc<Self>, vk::Result> {
let size_info = [
vk::DescriptorPoolSize {

15
source/framework/render/device.rs

@ -50,8 +50,7 @@ pub trait GetDevice {
}
fn enable_device_extensions(
physical: &PhysicalDevice,
extensions: &[crate::ffi::Nts],
physical: &PhysicalDevice, extensions: &[crate::ffi::Nts],
) -> Result<vk::DeviceCreateInfo, ErrDeviceCreate> {
if !extensions.is_empty() {
let props = unsafe {
@ -70,8 +69,7 @@ fn enable_device_extensions(
fn get_memory_type(
memory_props: vk::PhysicalDeviceMemoryProperties,
filter_flags: vk::MemoryPropertyFlags,
filter_types: u32,
filter_flags: vk::MemoryPropertyFlags, filter_types: u32,
) -> Result<u32, ErrAllocMem> {
let count = memory_props.memory_type_count as usize;
let iter = memory_props.memory_types.iter().take(count).enumerate();
@ -90,8 +88,7 @@ fn get_memory_type(
impl Device {
pub fn create(
physical: Rc<PhysicalDevice>,
qf_info: &QueueFamilyInfo,
physical: Rc<PhysicalDevice>, qf_info: &QueueFamilyInfo,
) -> Result<Rc<Self>, ErrDeviceCreate> {
const QUEUE_PRIORITY: [f32; 1] = [1.0];
@ -134,8 +131,7 @@ impl Device {
}
pub fn alloc_mem(
&self,
memory_reqs: vk::MemoryRequirements,
&self, memory_reqs: vk::MemoryRequirements,
memory_flags: vk::MemoryPropertyFlags,
) -> Result<vk::DeviceMemory, ErrAllocMem> {
unsafe {
@ -163,8 +159,7 @@ impl Device {
impl PhysicalDevice {
pub fn get(
instance: Rc<Instance>,
conf: &Conf,
instance: Rc<Instance>, conf: &Conf,
) -> Result<Rc<Self>, ErrPhysicalDeviceGet> {
let devs = unsafe { instance.enumerate_physical_devices()? };

3
source/framework/render/fence.rs

@ -25,8 +25,7 @@ impl Fence {
}
pub fn create_all(
device: Rc<Device>,
num: usize,
device: Rc<Device>, num: usize,
) -> Result<Vec<Rc<Self>>, vk::Result> {
(0..num).map(|_| Self::create(device.clone())).collect()
}

12
source/framework/render/framebuffer.rs

@ -18,10 +18,8 @@ impl GetDevice for Framebuffer {
impl Framebuffer {
pub fn create(
render_pass: Rc<RenderPass>,
image_view: Rc<ImageView>,
depth_view: Rc<ImageView>,
image_extent: vk::Extent2D,
render_pass: Rc<RenderPass>, image_view: Rc<ImageView>,
depth_view: Rc<ImageView>, image_extent: vk::Extent2D,
) -> Result<Rc<Self>, vk::Result> {
let attachments = [**image_view, **depth_view];
@ -43,10 +41,8 @@ impl Framebuffer {
}
pub fn create_all(
render_pass: Rc<RenderPass>,
image_views: &[Rc<ImageView>],
depth_view: Rc<ImageView>,
extent: vk::Extent2D,
render_pass: Rc<RenderPass>, image_views: &[Rc<ImageView>],
depth_view: Rc<ImageView>, extent: vk::Extent2D,
) -> Result<Vec<Rc<Self>>, vk::Result> {
image_views
.iter()

33
source/framework/render/image.rs

@ -59,8 +59,8 @@ impl GetDevice for IndepImage {
impl GetDevice for Image {
fn get_device(&self) -> &Rc<Device> {
match self {
Self::Owned(image) => image.get_device(),
Self::Indep(image) => image.get_device(),
| Self::Owned(image) => image.get_device(),
| Self::Indep(image) => image.get_device(),
}
}
}
@ -104,8 +104,7 @@ impl ImageInfo {
impl IndepImage {
pub fn create(
cmd_pool: &CommandPool,
mip: &MipImage,
cmd_pool: &CommandPool, mip: &MipImage,
) -> Result<Self, ErrAllocMem> {
let device = cmd_pool.get_device().clone();
@ -152,9 +151,7 @@ impl IndepImage {
}
pub fn create_depth(
cmd_pool: &CommandPool,
width: u32,
height: u32,
cmd_pool: &CommandPool, width: u32, height: u32,
) -> Result<Self, ErrAllocMem> {
let device = cmd_pool.get_device().clone();
@ -188,9 +185,7 @@ impl IndepImage {
}
fn layout_barrier(
&self,
cmd_pool: &CommandPool,
layout_stage: LayoutStage,
&self, cmd_pool: &CommandPool, layout_stage: LayoutStage,
) -> Result<(), vk::Result> {
let (
old_layout,
@ -200,7 +195,7 @@ impl IndepImage {
src_stage,
dst_stage,
) = match layout_stage {
LayoutStage::Xfer => (
| LayoutStage::Xfer => (
vk::ImageLayout::UNDEFINED,
vk::ImageLayout::TRANSFER_DST_OPTIMAL,
vk::AccessFlags::empty(),
@ -208,7 +203,7 @@ impl IndepImage {
vk::PipelineStageFlags::TOP_OF_PIPE,
vk::PipelineStageFlags::TRANSFER,
),
LayoutStage::Dpth => (
| LayoutStage::Dpth => (
vk::ImageLayout::UNDEFINED,
vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
vk::AccessFlags::empty(),
@ -217,7 +212,7 @@ impl IndepImage {
vk::PipelineStageFlags::TOP_OF_PIPE,
vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS,
),
LayoutStage::Frag => (
| LayoutStage::Frag => (
vk::ImageLayout::TRANSFER_DST_OPTIMAL,
vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
vk::AccessFlags::TRANSFER_WRITE,
@ -265,9 +260,7 @@ impl IndepImage {
}
fn copy_mips_to_image(
&self,
cmd_pool: &CommandPool,
mip: &MipImage,
&self, cmd_pool: &CommandPool, mip: &MipImage,
) -> Result<(), ErrAllocMem> {
let buffer =
Buffer::create_image(cmd_pool.get_device().clone(), mip.data())?;
@ -324,8 +317,8 @@ impl Image {
pub const fn info(&self) -> &ImageInfo {
match self {
Self::Owned(image) => &image.info,
Self::Indep(image) => &image.info,
| Self::Owned(image) => &image.info,
| Self::Indep(image) => &image.info,
}
}
}
@ -357,8 +350,8 @@ impl std::ops::Deref for Image {
type Target = vk::Image;
fn deref(&self) -> &Self::Target {
match self {
Self::Owned(image) => &image.handle,
Self::Indep(image) => &image.handle,
| Self::Owned(image) => &image.handle,
| Self::Indep(image) => &image.handle,
}
}
}

7
source/framework/render/instance.rs

@ -30,8 +30,7 @@ pub enum ErrInstanceCreate {
}
fn enable_instance_layers(
layers: &[crate::ffi::Nts],
entry: &ash::Entry,
layers: &[crate::ffi::Nts], entry: &ash::Entry,
) -> Result<vk::InstanceCreateInfo, ErrInstanceCreate> {
if !layers.is_empty() {
let props = entry.enumerate_instance_layer_properties()?;
@ -47,9 +46,7 @@ fn enable_instance_layers(
impl Instance {
pub fn create(
conf: &Conf,
entry: ash::Entry,
window: &hal::win::Window,
conf: &Conf, entry: ash::Entry, window: &hal::win::Window,
) -> Result<Rc<Self>, ErrInstanceCreate> {
let exts = window.vulkan_instance_extensions()?;

7
source/framework/render/model.rs

@ -26,8 +26,7 @@ impl GetDevice for Model {
impl Model {
pub fn create(
cmd_pool: &CommandPool,
model: data::model::Model,
cmd_pool: &CommandPool, model: data::model::Model,
model_data: data::model::ModelData,
) -> Result<Rc<Self>, ErrAllocMem> {
let vtx_buf = Buffer::create_vert(cmd_pool, &model_data.vtx)?;
@ -37,9 +36,7 @@ impl Model {
}
pub fn draw(
&self,
buf: vk::CommandBuffer,
mesh: &str,
&self, buf: vk::CommandBuffer, mesh: &str,
) -> Result<(), ErrModelDraw> {
// TODO: don't bother binding if already bound
unsafe {

6
source/framework/render/pipeline.rs

@ -21,10 +21,8 @@ impl GetDevice for Pipeline {
impl Pipeline {
pub fn create(
layout: Rc<PipelineLayout>,
render_pass: Rc<RenderPass>,
shader_vert: Rc<ShaderModule>,
shader_frag: Rc<ShaderModule>,
layout: Rc<PipelineLayout>, render_pass: Rc<RenderPass>,
shader_vert: Rc<ShaderModule>, shader_frag: Rc<ShaderModule>,
extent: vk::Extent2D,
) -> Result<Rc<Self>, vk::Result> {
let depth_stencil_state = vk::PipelineDepthStencilStateCreateInfo {

4
source/framework/render/properties.rs

@ -7,9 +7,7 @@ pub enum ErrProperty {
}
pub fn ensure_properties<T, F>(
props: &[T],
names: &[crate::ffi::Nts],
func: F,
props: &[T], names: &[crate::ffi::Nts], func: F,
) -> Result<(), ErrProperty>
where
F: Fn(&T) -> crate::ffi::Nts,

3
source/framework/render/queue.rs

@ -35,8 +35,7 @@ impl GetDevice for Queue {
impl QueueFamilyInfo {
pub fn collect(
physical: &PhysicalDevice,
surface: &Surface,
physical: &PhysicalDevice, surface: &Surface,
) -> Result<Self, ErrQueueFamilyCollect> {
let mut gfx_index = None;
let mut srf_index = None;

3
source/framework/render/renderpass.rs

@ -16,8 +16,7 @@ impl GetDevice for RenderPass {
impl RenderPass {
pub fn create(
device: Rc<Device>,
swapchain_format: vk::Format,
device: Rc<Device>, swapchain_format: vk::Format,
depth_format: vk::Format,
) -> Result<Rc<Self>, vk::Result> {
let attachments = [

3
source/framework/render/sampler.rs

@ -16,8 +16,7 @@ impl GetDevice for Sampler {
impl Sampler {
pub fn create(
device: Rc<Device>,
conf: &Conf,
device: Rc<Device>, conf: &Conf,
) -> Result<Rc<Self>, vk::Result> {
let create_info = vk::SamplerCreateInfo {
mag_filter: vk::Filter::NEAREST,

3
source/framework/render/semaphore.rs

@ -22,8 +22,7 @@ impl Semaphore {
}
pub fn create_all(
device: Rc<Device>,
num: usize,
device: Rc<Device>, num: usize,
) -> Result<Vec<Rc<Self>>, vk::Result> {
(0..num).map(|_| Self::create(device.clone())).collect()
}

3
source/framework/render/shader.rs

@ -16,8 +16,7 @@ impl GetDevice for ShaderModule {
impl ShaderModule {
pub fn create(
device: Rc<Device>,
spir: &Spir,
device: Rc<Device>, spir: &Spir,
) -> Result<Rc<Self>, vk::Result> {
let create_info = vk::ShaderModuleCreateInfo {
code_size: spir.size,

3
source/framework/render/surface.rs

@ -10,8 +10,7 @@ pub struct Surface {
impl Surface {
pub fn create(
instance: Rc<Instance>,
window: &hal::win::Window,
instance: Rc<Instance>, window: &hal::win::Window,
) -> Result<Rc<Self>, hal::Err> {
let handle = window.vulkan_create_surface(&instance)?;
Ok(Rc::new(Self { handle, instance }))

6
source/framework/render/swapchain.rs

@ -24,10 +24,8 @@ impl GetDevice for Swapchain {
impl Swapchain {
pub fn create(
queue_graphics: Rc<Queue>,
queue_surface: Rc<Queue>,
surface: Rc<Surface>,
conf: &Conf,
queue_graphics: Rc<Queue>, queue_surface: Rc<Queue>,
surface: Rc<Surface>, conf: &Conf,
) -> Result<Rc<Self>, vk::Result> {
let device = &queue_graphics.device;

21
source/framework/vire/compiler/function.rs

@ -36,36 +36,36 @@ impl<'a> IncompleteFunction<'a> {
unsafe {
match datum {
Datum::Null => {
| Datum::Null => {
Ok(LLVMGetUndef(self.contx.basic_type(Basic::Void).handle()))
}
Datum::Bool(value) => Ok(LLVMConstInt(
| Datum::Bool(value) => Ok(LLVMConstInt(
self.contx.basic_type(Basic::Bool).handle(),
*value as _,
0,
)),
Datum::Char(character) => Ok(LLVMConstInt(
| Datum::Char(character) => Ok(LLVMConstInt(
self.contx.basic_type(Basic::Q32_0U).handle(),
*character as _,
0,
)),
Datum::Strn(_) => {
| Datum::Strn(_) => {
// TODO
Err(Err::Syntax)
}
Datum::Symb(name) => {
| Datum::Symb(name) => {
// TODO: must support more than global function symbols
let name = CString::new(name.as_bytes()).unwrap().into_raw();
let func = LLVMGetNamedFunction(self.contx.modul, name);
CString::from_raw(name);
Ok(func)
}
Datum::Numb(number) => Ok(LLVMConstInt(
| Datum::Numb(number) => Ok(LLVMConstInt(
self.contx.basic_type(Basic::Q64_0).handle(),
*number as _,
0,
)),
Datum::Cons { cdr, car } => {
| Datum::Cons { cdr, car } => {
// function call
let func = self.compile(car)?;
let mut args = Vec::new();
@ -89,8 +89,7 @@ impl<'a> IncompleteFunction<'a> {
}
pub fn begin_context(
&mut self,
block: impl FnOnce(&mut Self) -> Result<(), Err>,
&mut self, block: impl FnOnce(&mut Self) -> Result<(), Err>,
) -> Result<(), Err> {
unsafe {
LLVMPositionBuilderAtEnd(self.contx.build, self.block);
@ -148,8 +147,8 @@ impl<'a> IncompleteFunction<'a> {
Ok(Function::new(self.value))
} else {
match res {
Ok(error_message) => Err(Err::VerifyFunc(error_message)),
Err(err) => Err(Err::VerifyFunc(err.to_string())),
| Ok(error_message) => Err(Err::VerifyFunc(error_message)),
| Err(err) => Err(Err::VerifyFunc(err.to_string())),
}
}
} else {

20
source/framework/vire/compiler/types.rs

@ -84,16 +84,16 @@ impl BasicType {
pub fn new(btyp: Basic) -> Self {
let handle = unsafe {
match btyp {
Basic::Void => LLVMVoidType(),
Basic::Bool => LLVMInt1Type(),
Basic::Q8_0 | Basic::Q8_0U => LLVMInt8Type(),
Basic::Q16_0 | Basic::Q16_0U | Basic::Q16 | Basic::Q16U => {
| Basic::Void => LLVMVoidType(),
| Basic::Bool => LLVMInt1Type(),
| Basic::Q8_0 | Basic::Q8_0U => LLVMInt8Type(),
| Basic::Q16_0 | Basic::Q16_0U | Basic::Q16 | Basic::Q16U => {
LLVMInt16Type()
}
Basic::Q32_0 | Basic::Q32_0U | Basic::Q24_8 | Basic::Q24_8U => {
| Basic::Q32_0 | Basic::Q32_0U | Basic::Q24_8 | Basic::Q24_8U => {
LLVMInt32Type()
}
Basic::Q64_0 | Basic::Q64_0U => LLVMInt64Type(),
| Basic::Q64_0 | Basic::Q64_0U => LLVMInt64Type(),
}
};
Self { btyp, handle }
@ -161,10 +161,10 @@ impl TypeHandle for FunctType {
impl TypeHandle for ComplType