Browse Source

remove failure dependency

master
Alison Watson 3 years ago
parent
commit
61e3326d0c
  1. 6
      Cargo.toml
  2. 6
      source/main.rs
  3. 55
      source/render/instance.rs
  4. 11
      source/render/pipeline.rs
  5. 10
      source/render/shader.rs
  6. 4
      source/render/surface.rs
  7. 1
      source/util.rs
  8. 5
      source/util/err.rs

6
Cargo.toml

@ -12,7 +12,7 @@ publish = false
build = "source/build.rs"
[features]
default = ["color-log"]
default = ["color-log"]
color-log = ["termcolor"]
[dependencies]
@ -20,10 +20,6 @@ ash = "0.29"
sdl2-sys = "0.32"
serde_yaml = "0.8"
[dependencies.failure]
version = "0.1"
features = ["std"]
[dependencies.termcolor]
version = "1.0"
optional = true

6
source/main.rs

@ -117,12 +117,10 @@ fn fallback_main(
conf: &conf::Conf,
lg: &log::Log,
) -> Result<(), Box<dyn std::error::Error>> {
let hal = hal::Context::new()?;
let hal = hal::Context::new()?;
let window = hal::Window::new(&hal, meta::ffi::name(), 640, 480)?;
let entry = ash::Entry::new()?;
let entry = ash::Entry::new()?;
let instance = Instance::create(&conf.render, &entry, &window)?;
let phys_device = PhysicalDevice::get(&instance, &conf.render)?;

55
source/render/instance.rs

@ -1,8 +1,10 @@
use crate::{
render::{ensure_properties, Conf},
util::{err, meta},
hal::ErrSdl,
render::{ensure_properties, Conf, ErrNoProperty},
util::meta,
};
use ash::{
InstanceError,
extensions::khr,
version::{EntryV1_0, InstanceV1_0},
vk, vk_make_version,
@ -15,10 +17,18 @@ pub struct Instance {
pub surface_ext: khr::Surface,
}
#[derive(Debug)]
pub enum ErrInstanceCreate {
Vk(vk::Result),
Instance(InstanceError),
NoExtension(ErrNoProperty),
Sdl(ErrSdl),
}
fn enable_instance_layers(
layers: &[*const c_char],
entry: &ash::Entry,
) -> err::Result<vk::InstanceCreateInfo> {
) -> Result<vk::InstanceCreateInfo, ErrInstanceCreate> {
if layers.len() > 0 {
let props = entry.enumerate_instance_layer_properties()?;
ensure_properties(&props, layers, |x| x.layer_name.as_ptr())?;
@ -36,7 +46,7 @@ impl Instance {
conf: &Conf,
entry: &ash::Entry,
window: &crate::hal::Window,
) -> err::Result<Self> {
) -> Result<Self, ErrInstanceCreate> {
let exts = window.vulkan_instance_extensions()?;
let app_info = vk::ApplicationInfo {
@ -79,4 +89,41 @@ impl std::ops::Deref for Instance {
}
}
impl std::fmt::Display for ErrInstanceCreate {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Vk(res) => res.fmt(f),
Self::Instance(err) => err.fmt(f),
Self::NoExtension(err) => write!(f, "Missing extension: {}", err),
Self::Sdl(err) => err.fmt(f),
}
}
}
impl std::error::Error for ErrInstanceCreate {}
impl From<vk::Result> for ErrInstanceCreate {
fn from(res: vk::Result) -> Self {
Self::Vk(res)
}
}
impl From<InstanceError> for ErrInstanceCreate {
fn from(err: InstanceError) -> Self {
Self::Instance(err)
}
}
impl From<ErrNoProperty> for ErrInstanceCreate {
fn from(err: ErrNoProperty) -> Self {
Self::NoExtension(err)
}
}
impl From<ErrSdl> for ErrInstanceCreate {
fn from(err: ErrSdl) -> Self {
Self::Sdl(err)
}
}
// EOF

11
source/render/pipeline.rs

@ -1,7 +1,4 @@
use crate::{
render::{Device, ShaderModule},
util::err,
};
use crate::render::{Device, ShaderModule};
use ash::{version::DeviceV1_0, vk};
pub struct PipelineLayout<'a, 'b> {
@ -20,7 +17,7 @@ pub struct Pipeline<'a, 'b> {
}
impl<'a, 'b> PipelineLayout<'a, 'b> {
pub fn create(device: &'a Device<'b>) -> err::Result<Self> {
pub fn create(device: &'a Device<'b>) -> Result<Self, vk::Result> {
let create_info = vk::PipelineLayoutCreateInfo::default();
let handle =
@ -33,7 +30,7 @@ impl<'a, 'b> RenderPass<'a, 'b> {
pub fn create(
device: &'a Device<'b>,
format: vk::Format,
) -> err::Result<Self> {
) -> Result<Self, vk::Result> {
let attachments = [
vk::AttachmentDescription {
format,
@ -101,7 +98,7 @@ impl<'a, 'b> Pipeline<'a, 'b> {
shader_vert: &ShaderModule,
shader_frag: &ShaderModule,
extent: vk::Extent2D,
) -> err::Result<Vec<Self>> {
) -> Result<Vec<Self>, vk::Result> {
let shader_stages = [
vk::PipelineShaderStageCreateInfo {
stage: vk::ShaderStageFlags::VERTEX,

10
source/render/shader.rs

@ -1,7 +1,4 @@
use crate::{
render::{Device, Spir},
util::err,
};
use crate::render::{Device, Spir};
use ash::{version::DeviceV1_0, vk};
pub struct ShaderModule<'a, 'b> {
@ -10,7 +7,10 @@ pub struct ShaderModule<'a, 'b> {
}
impl<'a, 'b> ShaderModule<'a, 'b> {
pub fn create(device: &'a Device<'b>, spir: &Spir) -> err::Result<Self> {
pub fn create(
device: &'a Device<'b>,
spir: &Spir,
) -> Result<Self, vk::Result> {
let create_info = vk::ShaderModuleCreateInfo {
code_size: spir.size,
p_code: spir.code.as_ptr(),

4
source/render/surface.rs

@ -1,4 +1,4 @@
use crate::{render::Instance, util::err};
use crate::render::Instance;
use ash::vk;
pub struct Surface<'a> {
@ -10,7 +10,7 @@ impl<'a> Surface<'a> {
pub fn create(
instance: &'a Instance,
window: &crate::hal::Window,
) -> err::Result<Self> {
) -> Result<Self, crate::hal::ErrSdl> {
let handle = window.vulkan_create_surface(instance)?;
Ok(Self { instance, handle })
}

1
source/util.rs

@ -29,7 +29,6 @@ pub mod ffi;
#[macro_use]
pub mod log;
pub mod err;
pub mod meta;
// EOF

5
source/util/err.rs

@ -1,5 +0,0 @@
pub use failure::err_msg as static_msg;
use failure::Error;
pub type Result<T> = std::result::Result<T, Error>;
Loading…
Cancel
Save