chore: general cleanup
This commit is contained in:
parent
6c593dda79
commit
19e8da7d85
|
@ -61,7 +61,7 @@ pub type PFN_libra_error_errno = extern "C" fn(error: libra_error_t) -> LIBRA_ER
|
|||
///
|
||||
/// ## Safety
|
||||
/// - `error` must be valid and initialized.
|
||||
pub extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO {
|
||||
pub unsafe extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO {
|
||||
let Some(error) = error else {
|
||||
return LIBRA_ERRNO::UNKNOWN_ERROR
|
||||
};
|
||||
|
@ -77,7 +77,7 @@ pub type PFN_libra_error_print = extern "C" fn(error: libra_error_t) -> i32;
|
|||
/// If `error` is null, this function does nothing and returns 1. Otherwise, this function returns 0.
|
||||
/// ## Safety
|
||||
/// - `error` must be a valid and initialized instance of `libra_error_t`.
|
||||
pub extern "C" fn libra_error_print(error: libra_error_t) -> i32 {
|
||||
pub unsafe extern "C" fn libra_error_print(error: libra_error_t) -> i32 {
|
||||
let Some(error) = error else {
|
||||
return 1
|
||||
};
|
||||
|
@ -85,7 +85,7 @@ pub extern "C" fn libra_error_print(error: libra_error_t) -> i32 {
|
|||
let error = error.as_ref();
|
||||
println!("{error:?}: {error}");
|
||||
}
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
|
||||
/// Function pointer definition for libra_error_free
|
||||
|
@ -97,7 +97,7 @@ pub type PFN_libra_error_free = extern "C" fn(error: *mut libra_error_t) -> i32;
|
|||
/// The resulting error object becomes null.
|
||||
/// ## Safety
|
||||
/// - `error` must be null or a pointer to a valid and initialized instance of `libra_error_t`.
|
||||
pub extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 {
|
||||
pub unsafe extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 {
|
||||
if error.is_null() {
|
||||
return 1;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ pub extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 {
|
|||
};
|
||||
|
||||
unsafe { drop(Box::from_raw(error.as_ptr())) }
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
|
||||
/// Function pointer definition for libra_error_write
|
||||
|
@ -122,7 +122,7 @@ pub type PFN_libra_error_write =
|
|||
/// ## Safety
|
||||
/// - `error` must be a valid and initialized instance of `libra_error_t`.
|
||||
/// - `out` must be a non-null pointer. The resulting string must not be modified.
|
||||
pub extern "C" fn libra_error_write(
|
||||
pub unsafe extern "C" fn libra_error_write(
|
||||
error: libra_error_t,
|
||||
out: *mut MaybeUninit<*mut c_char>,
|
||||
) -> i32 {
|
||||
|
@ -141,7 +141,7 @@ pub extern "C" fn libra_error_write(
|
|||
|
||||
out.write(MaybeUninit::new(cstring.into_raw()))
|
||||
}
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
|
||||
/// Function pointer definition for libra_error_free_string
|
||||
|
@ -154,7 +154,7 @@ pub type PFN_libra_error_free_string = extern "C" fn(out: *mut *mut c_char) -> i
|
|||
/// - If `libra_error_write` is not null, it must point to a string previously returned by `libra_error_write`.
|
||||
/// Attempting to free anything else, including strings or objects from other librashader functions, is immediate
|
||||
/// Undefined Behaviour.
|
||||
pub extern "C" fn libra_error_free_string(out: *mut *mut c_char) -> i32 {
|
||||
pub unsafe extern "C" fn libra_error_free_string(out: *mut *mut c_char) -> i32 {
|
||||
if out.is_null() {
|
||||
return 1;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ pub extern "C" fn libra_error_free_string(out: *mut *mut c_char) -> i32 {
|
|||
*out = std::ptr::null_mut();
|
||||
drop(CString::from_raw(ptr))
|
||||
}
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
|
||||
impl LibrashaderError {
|
||||
|
|
|
@ -67,7 +67,7 @@ macro_rules! extern_fn {
|
|||
|
||||
#[no_mangle]
|
||||
$(#[$($attrss)*])*
|
||||
pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
$crate::ffi::ffi_body!($body)
|
||||
}
|
||||
};
|
||||
|
@ -81,7 +81,7 @@ macro_rules! extern_fn {
|
|||
|
||||
#[no_mangle]
|
||||
$(#[$($attrss)*])*
|
||||
pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
$body
|
||||
}
|
||||
};
|
||||
|
@ -95,7 +95,7 @@ macro_rules! extern_fn {
|
|||
|
||||
#[no_mangle]
|
||||
$(#[$($attrss)*])*
|
||||
pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
$crate::ffi::ffi_body!(|$($ref_capture),*|; mut |$($mut_capture),*| $body)
|
||||
}
|
||||
};
|
||||
|
@ -109,7 +109,7 @@ macro_rules! extern_fn {
|
|||
|
||||
#[no_mangle]
|
||||
$(#[$($attrss)*])*
|
||||
pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
$crate::ffi::ffi_body!(mut |$($mut_capture),*| $body)
|
||||
}
|
||||
};
|
||||
|
@ -122,7 +122,7 @@ macro_rules! extern_fn {
|
|||
|
||||
#[no_mangle]
|
||||
$(#[$($attrss)*])*
|
||||
pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t {
|
||||
$crate::ffi::ffi_body!(|$($ref_capture),*| $body)
|
||||
}
|
||||
};
|
||||
|
|
|
@ -35,7 +35,7 @@ impl TryFrom<libra_source_image_d3d11_t> for D3D11InputView {
|
|||
assert_non_null!(noexport handle);
|
||||
|
||||
Ok(D3D11InputView {
|
||||
handle: unsafe { (&*handle).clone() },
|
||||
handle: unsafe { (*handle).clone() },
|
||||
size: Size::new(value.width, value.height),
|
||||
})
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ extern_fn! {
|
|||
y: viewport.y,
|
||||
output: D3D11OutputView {
|
||||
size: Size::new(viewport.width, viewport.height),
|
||||
handle: unsafe { (&*out).clone() },
|
||||
handle: unsafe { (*out).clone() },
|
||||
},
|
||||
mvp,
|
||||
};
|
||||
|
@ -152,7 +152,7 @@ extern_fn! {
|
|||
let name = CStr::from_ptr(param_name);
|
||||
let name = name.to_str()?;
|
||||
|
||||
if let None = chain.set_parameter(name, value) {
|
||||
if chain.set_parameter(name, value).is_none() {
|
||||
return LibrashaderError::UnknownShaderParameter(param_name).export()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ extern_fn! {
|
|||
let name = CStr::from_ptr(param_name);
|
||||
let name = name.to_str()?;
|
||||
|
||||
if let None = chain.set_parameter(name, value) {
|
||||
if chain.set_parameter(name, value).is_none() {
|
||||
return LibrashaderError::UnknownShaderParameter(param_name).export()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ extern_fn! {
|
|||
let name = CStr::from_ptr(param_name);
|
||||
let name = name.to_str()?;
|
||||
|
||||
if let None = chain.set_parameter(name, value) {
|
||||
if chain.set_parameter(name, value).is_none() {
|
||||
return LibrashaderError::UnknownShaderParameter(param_name).export()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ impl ShaderPassConfig {
|
|||
} else if self.float_framebuffer {
|
||||
return Some(ImageFormat::R16G16B16A16Sfloat);
|
||||
}
|
||||
return None;
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use librashader_presets::ShaderPassConfig;
|
|||
use librashader_reflect::back::cross::CrossHlslContext;
|
||||
use librashader_reflect::back::ShaderCompilerOutput;
|
||||
use librashader_reflect::reflect::semantics::{
|
||||
BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics,
|
||||
BindingStage, MemberOffset, TextureBinding, UniformBinding,
|
||||
};
|
||||
use librashader_reflect::reflect::ShaderReflection;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
@ -94,18 +94,6 @@ impl FilterPass {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_texture(
|
||||
samplers: &SamplerSet,
|
||||
texture_binding: &mut [Option<ID3D11ShaderResourceView>; 16],
|
||||
sampler_binding: &mut [Option<ID3D11SamplerState>; 16],
|
||||
binding: &TextureBinding,
|
||||
texture: &InputTexture,
|
||||
) {
|
||||
texture_binding[binding.binding as usize] = Some(texture.view.handle.clone());
|
||||
sampler_binding[binding.binding as usize] =
|
||||
Some(samplers.get(texture.wrap_mode, texture.filter).clone());
|
||||
}
|
||||
|
||||
// framecount should be pre-modded
|
||||
fn build_semantics<'a>(
|
||||
&mut self,
|
||||
|
@ -175,7 +163,7 @@ impl FilterPass {
|
|||
|
||||
let mut textures: [Option<ID3D11ShaderResourceView>; 16] = std::array::from_fn(|_| None);
|
||||
let mut samplers: [Option<ID3D11SamplerState>; 16] = std::array::from_fn(|_| None);
|
||||
let mut descriptors = (&mut textures, &mut samplers);
|
||||
let descriptors = (&mut textures, &mut samplers);
|
||||
|
||||
self.build_semantics(
|
||||
pass_index,
|
||||
|
|
|
@ -39,7 +39,7 @@ impl FilterChainGL {
|
|||
})
|
||||
});
|
||||
match result {
|
||||
Err(_) => return Err(FilterChainError::GLLoadError),
|
||||
Err(_) => Err(FilterChainError::GLLoadError),
|
||||
Ok(res) => res,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use librashader_common::{ImageFormat, Size, Viewport};
|
|||
use librashader_preprocess::ShaderSource;
|
||||
use librashader_presets::ShaderPassConfig;
|
||||
use librashader_reflect::reflect::semantics::{
|
||||
MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics,
|
||||
MemberOffset, TextureBinding, UniformBinding,
|
||||
};
|
||||
use librashader_runtime::binding::{BindSemantics, ContextOffset, TextureInput};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
@ -74,7 +74,7 @@ impl<T: GLInterface> BindSemantics<GlUniformBinder, UniformLocation<GLint>> for
|
|||
texture: &Self::InputTexture,
|
||||
_device: &Self::DeviceContext,
|
||||
) {
|
||||
T::BindTexture::bind_texture(&samplers, binding, texture);
|
||||
T::BindTexture::bind_texture(samplers, binding, texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,7 @@ use librashader_common::{Size, Viewport};
|
|||
|
||||
use crate::filter_chain::FilterChainGL;
|
||||
use crate::framebuffer::GLImage;
|
||||
use crate::gl::gl3::CompatibilityGL;
|
||||
use crate::gl::{FramebufferInterface, GLInterface};
|
||||
|
||||
use crate::Framebuffer;
|
||||
|
||||
const WIDTH: u32 = 800;
|
||||
|
|
|
@ -9,8 +9,7 @@ use librashader_common::{Size, Viewport};
|
|||
|
||||
use crate::filter_chain::FilterChainGL;
|
||||
use crate::framebuffer::GLImage;
|
||||
use crate::gl::gl46::DirectStateAccessGL;
|
||||
use crate::gl::{FramebufferInterface, GLInterface};
|
||||
|
||||
use crate::Framebuffer;
|
||||
|
||||
const WIDTH: u32 = 800;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::framebuffer::GLImage;
|
||||
use gl::types::GLuint;
|
||||
|
||||
use librashader_common::{FilterMode, WrapMode};
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone)]
|
||||
|
@ -18,7 +18,7 @@ impl InputTexture {
|
|||
/// Returns a reference to itself if the texture is bound.
|
||||
pub fn bound(&self) -> Option<&Self> {
|
||||
if self.is_bound() {
|
||||
Some(&self)
|
||||
Some(self)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -505,7 +505,7 @@ impl FilterChainVulkan {
|
|||
// eprintln!("[history] using frame history with {required_images} images");
|
||||
let mut images = Vec::with_capacity(required_images);
|
||||
images.resize_with(required_images, || {
|
||||
OwnedImage::new(&vulkan, Size::new(1, 1), ImageFormat::R8G8B8A8Unorm, 1)
|
||||
OwnedImage::new(vulkan, Size::new(1, 1), ImageFormat::R8G8B8A8Unorm, 1)
|
||||
});
|
||||
|
||||
let images: error::Result<Vec<OwnedImage>> = images.into_iter().collect();
|
||||
|
@ -553,7 +553,7 @@ impl FilterChainVulkan {
|
|||
vk::QUEUE_FAMILY_IGNORED,
|
||||
);
|
||||
|
||||
back.copy_from(cmd, &input, vk::ImageLayout::TRANSFER_SRC_OPTIMAL);
|
||||
back.copy_from(cmd, input, vk::ImageLayout::TRANSFER_SRC_OPTIMAL);
|
||||
|
||||
util::vulkan_image_layout_transition_levels(
|
||||
&self.vulkan.device,
|
||||
|
@ -729,7 +729,7 @@ impl FilterChainVulkan {
|
|||
frame_direction,
|
||||
viewport,
|
||||
&original,
|
||||
&source,
|
||||
source,
|
||||
&out,
|
||||
)?;
|
||||
|
||||
|
@ -739,7 +739,7 @@ impl FilterChainVulkan {
|
|||
out.output.end_pass(cmd);
|
||||
}
|
||||
|
||||
source = &self.common.output_inputs[index].as_ref().unwrap();
|
||||
source = self.common.output_inputs[index].as_ref().unwrap();
|
||||
intermediates.dispose_outputs(out.output);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,12 @@ use librashader_common::{ImageFormat, Size, Viewport};
|
|||
use librashader_preprocess::ShaderSource;
|
||||
use librashader_presets::ShaderPassConfig;
|
||||
use librashader_reflect::reflect::semantics::{
|
||||
BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics,
|
||||
BindingStage, MemberOffset, TextureBinding, UniformBinding,
|
||||
};
|
||||
use librashader_reflect::reflect::ShaderReflection;
|
||||
use librashader_runtime::binding::{BindSemantics, TextureInput};
|
||||
use librashader_runtime::uniforms::{
|
||||
BindUniform, NoUniformBinder, UniformStorage, UniformStorageAccess,
|
||||
UniformStorage, UniformStorageAccess,
|
||||
};
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::sync::Arc;
|
||||
|
@ -46,6 +46,7 @@ impl BindSemantics for FilterPass {
|
|||
type DeviceContext = Arc<ash::Device>;
|
||||
type UniformOffset = MemberOffset;
|
||||
|
||||
#[inline(always)]
|
||||
fn bind_texture<'a>(
|
||||
descriptors: &mut Self::DescriptorSet<'a>,
|
||||
samplers: &Self::SamplerSet,
|
||||
|
@ -74,33 +75,6 @@ impl BindSemantics for FilterPass {
|
|||
}
|
||||
|
||||
impl FilterPass {
|
||||
#[inline(always)]
|
||||
fn bind_texture(
|
||||
device: &ash::Device,
|
||||
samplers: &SamplerSet,
|
||||
descriptor_set: vk::DescriptorSet,
|
||||
binding: &TextureBinding,
|
||||
texture: &InputImage,
|
||||
) {
|
||||
let sampler = samplers.get(texture.wrap_mode, texture.filter_mode, texture.mip_filter);
|
||||
let image_info = [vk::DescriptorImageInfo::builder()
|
||||
.sampler(sampler.handle)
|
||||
.image_view(texture.image_view)
|
||||
.image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)
|
||||
.build()];
|
||||
|
||||
let write_desc = [vk::WriteDescriptorSet::builder()
|
||||
.dst_set(descriptor_set)
|
||||
.dst_binding(binding.binding)
|
||||
.dst_array_element(0)
|
||||
.descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER)
|
||||
.image_info(&image_info)
|
||||
.build()];
|
||||
unsafe {
|
||||
device.update_descriptor_sets(&write_desc, &[]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_format(&self) -> ImageFormat {
|
||||
let fb_format = self.source.format;
|
||||
if let Some(format) = self.config.get_format_override() {
|
||||
|
@ -124,13 +98,13 @@ impl FilterPass {
|
|||
source: &InputImage,
|
||||
output: &RenderTarget,
|
||||
) -> error::Result<()> {
|
||||
let mut descriptor = *&self.graphics_pipeline.layout.descriptor_sets
|
||||
let mut descriptor = self.graphics_pipeline.layout.descriptor_sets
|
||||
[(frame_count % self.frames_in_flight) as usize];
|
||||
|
||||
self.build_semantics(
|
||||
pass_index,
|
||||
parent,
|
||||
&output.mvp,
|
||||
output.mvp,
|
||||
frame_count,
|
||||
frame_direction,
|
||||
output.output.size,
|
||||
|
@ -231,7 +205,7 @@ impl FilterPass {
|
|||
frame_direction: i32,
|
||||
fb_size: Size<u32>,
|
||||
viewport_size: Size<u32>,
|
||||
mut descriptor_set: &mut vk::DescriptorSet,
|
||||
descriptor_set: &mut vk::DescriptorSet,
|
||||
original: &InputImage,
|
||||
source: &InputImage,
|
||||
) {
|
||||
|
@ -239,7 +213,7 @@ impl FilterPass {
|
|||
&self.device,
|
||||
&parent.samplers,
|
||||
&mut self.uniform_storage,
|
||||
&mut descriptor_set,
|
||||
descriptor_set,
|
||||
mvp,
|
||||
frame_count,
|
||||
frame_direction,
|
||||
|
|
|
@ -33,7 +33,7 @@ impl OutputImage {
|
|||
let view_info = vk::ImageViewCreateInfo::builder()
|
||||
.view_type(vk::ImageViewType::TYPE_2D)
|
||||
.format(image.format)
|
||||
.image(image.image.clone())
|
||||
.image(image.image)
|
||||
.subresource_range(image_subresource)
|
||||
.components(swizzle_components)
|
||||
.build();
|
||||
|
|
|
@ -12,7 +12,7 @@ pub struct VulkanCommandPool {
|
|||
|
||||
impl VulkanCommandPool {
|
||||
pub fn new(base: &VulkanBase, frames_in_flight: u32) -> VkResult<VulkanCommandPool> {
|
||||
let indices = find_queue_family(&base.instance, base.physical_device.clone());
|
||||
let indices = find_queue_family(&base.instance, base.physical_device);
|
||||
|
||||
let create_info = vk::CommandPoolCreateInfo::builder()
|
||||
.flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::hello_triangle::swapchain::VulkanSwapchain;
|
||||
|
||||
use ash::prelude::VkResult;
|
||||
use ash::vk;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ mod swapchain;
|
|||
mod syncobjects;
|
||||
pub mod vulkan_base;
|
||||
|
||||
use crate::filter_chain::{FilterChainVulkan, VulkanObjects};
|
||||
use crate::filter_chain::{FilterChainVulkan};
|
||||
use crate::hello_triangle::command::VulkanCommandPool;
|
||||
use crate::hello_triangle::framebuffer::VulkanFramebuffer;
|
||||
use crate::hello_triangle::pipeline::VulkanPipeline;
|
||||
|
@ -19,15 +19,15 @@ use crate::hello_triangle::vulkan_base::VulkanBase;
|
|||
use crate::texture::VulkanImage;
|
||||
use crate::util;
|
||||
use ash::vk;
|
||||
use ash::vk::{Handle, RenderingInfo};
|
||||
|
||||
use librashader_common::Viewport;
|
||||
use std::ffi::CString;
|
||||
|
||||
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
|
||||
use winit::platform::windows::EventLoopBuilderExtWindows;
|
||||
|
||||
// Constants
|
||||
const WINDOW_TITLE: &'static str = "librashader Vulkan";
|
||||
const WINDOW_TITLE: &str = "librashader Vulkan";
|
||||
const WINDOW_WIDTH: u32 = 800;
|
||||
const WINDOW_HEIGHT: u32 = 600;
|
||||
const MAX_FRAMES_IN_FLIGHT: usize = 3;
|
||||
|
@ -384,7 +384,7 @@ pub fn main(vulkan: VulkanBase, filter_chain: FilterChainVulkan) {
|
|||
let pipeline = unsafe { VulkanPipeline::new(&vulkan, &swapchain) }.unwrap();
|
||||
|
||||
let mut render_framebuffers = vec![];
|
||||
for (index, image) in swapchain.render_image_views.iter().enumerate() {
|
||||
for (_index, image) in swapchain.render_image_views.iter().enumerate() {
|
||||
render_framebuffers.push(
|
||||
VulkanFramebuffer::new(
|
||||
&vulkan.device,
|
||||
|
|
|
@ -24,10 +24,8 @@ pub(crate) fn pick_physical_device(instance: &ash::Instance) -> vk::PhysicalDevi
|
|||
|
||||
let mut result = None;
|
||||
for &physical_device in physical_devices.iter() {
|
||||
if is_physical_device_suitable(instance, physical_device) {
|
||||
if result.is_none() {
|
||||
result = Some(physical_device)
|
||||
}
|
||||
if is_physical_device_suitable(instance, physical_device) && result.is_none() {
|
||||
result = Some(physical_device)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +111,7 @@ fn is_physical_device_suitable(
|
|||
|
||||
let indices = find_queue_family(instance, physical_device);
|
||||
|
||||
return indices.is_complete();
|
||||
indices.is_complete()
|
||||
}
|
||||
|
||||
pub fn find_queue_family(
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use crate::hello_triangle::find_memorytype_index;
|
||||
use crate::hello_triangle::surface::VulkanSurface;
|
||||
|
||||
use crate::hello_triangle::swapchain::VulkanSwapchain;
|
||||
use crate::hello_triangle::vulkan_base::VulkanBase;
|
||||
use ash::prelude::VkResult;
|
||||
use ash::util::{read_spv, Align};
|
||||
use ash::vk;
|
||||
use bytemuck::offset_of;
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::io::Cursor;
|
||||
use std::mem::align_of;
|
||||
const ENTRY_POINT: &'static CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") };
|
||||
const ENTRY_POINT: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") };
|
||||
|
||||
#[derive(Default, Clone, Debug, Copy)]
|
||||
struct Vertex {
|
||||
|
|
|
@ -65,11 +65,11 @@ impl VulkanSurface {
|
|||
if available_format.format == vk::Format::B8G8R8A8_SRGB
|
||||
&& available_format.color_space == vk::ColorSpaceKHR::SRGB_NONLINEAR
|
||||
{
|
||||
return Ok(available_format.clone());
|
||||
return Ok(*available_format);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(available_formats.first().unwrap().clone());
|
||||
return Ok(*available_formats.first().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ use crate::util::find_vulkan_memory_type;
|
|||
use crate::vulkan_primitives::VulkanImageMemory;
|
||||
use ash::prelude::VkResult;
|
||||
use ash::vk;
|
||||
use ash::vk::{Extent3D, Handle};
|
||||
use std::ffi::CStr;
|
||||
use ash::vk::{Extent3D};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct VulkanSwapchain {
|
||||
|
@ -93,7 +93,7 @@ impl VulkanSwapchain {
|
|||
|
||||
unsafe {
|
||||
let image = base.device.create_image(&create_info, None)?;
|
||||
let mem_reqs = unsafe { base.device.get_image_memory_requirements(image.clone()) };
|
||||
let mem_reqs = unsafe { base.device.get_image_memory_requirements(image) };
|
||||
|
||||
// base.debug
|
||||
// .loader
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
use ash::vk;
|
||||
use std::borrow::Cow;
|
||||
use std::error::Error;
|
||||
|
||||
|
||||
|
||||
use crate::error::FilterChainError;
|
||||
use crate::filter_chain::VulkanObjects;
|
||||
use crate::hello_triangle::debug::VulkanDebug;
|
||||
use crate::hello_triangle::physicaldevice::{find_queue_family, pick_physical_device};
|
||||
use crate::hello_triangle::surface::VulkanSurface;
|
||||
|
||||
use ash::prelude::VkResult;
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::ffi::{CStr};
|
||||
use std::sync::Arc;
|
||||
|
||||
const WINDOW_TITLE: &'static [u8] = b"librashader Vulkan\0";
|
||||
const KHRONOS_VALIDATION: &'static [u8] = b"VK_LAYER_KHRONOS_validation\0";
|
||||
const WINDOW_TITLE: &[u8] = b"librashader Vulkan\0";
|
||||
const KHRONOS_VALIDATION: &[u8] = b"VK_LAYER_KHRONOS_validation\0";
|
||||
|
||||
pub struct VulkanBase {
|
||||
pub entry: ash::Entry,
|
||||
|
@ -27,8 +27,8 @@ pub struct VulkanBase {
|
|||
impl VulkanBase {
|
||||
pub fn new(entry: ash::Entry) -> VkResult<VulkanBase> {
|
||||
let app_info = vk::ApplicationInfo::builder()
|
||||
.application_name(unsafe { &CStr::from_bytes_with_nul_unchecked(WINDOW_TITLE) })
|
||||
.engine_name(unsafe { &CStr::from_bytes_with_nul_unchecked(WINDOW_TITLE) })
|
||||
.application_name(unsafe { CStr::from_bytes_with_nul_unchecked(WINDOW_TITLE) })
|
||||
.engine_name(unsafe { CStr::from_bytes_with_nul_unchecked(WINDOW_TITLE) })
|
||||
.engine_version(0)
|
||||
.application_version(0)
|
||||
.api_version(vk::make_api_version(0, 1, 3, 0))
|
||||
|
@ -80,7 +80,7 @@ impl VulkanBase {
|
|||
) -> VkResult<(ash::Device, vk::Queue)> {
|
||||
let debug = [unsafe { CStr::from_bytes_with_nul_unchecked(KHRONOS_VALIDATION).as_ptr() }];
|
||||
|
||||
let indices = find_queue_family(&instance, *physical_device);
|
||||
let indices = find_queue_family(instance, *physical_device);
|
||||
let queue_info = [vk::DeviceQueueCreateInfo::builder()
|
||||
.queue_family_index(indices.graphics_family())
|
||||
.queue_priorities(&[1.0f32])
|
||||
|
@ -119,9 +119,9 @@ impl VulkanBase {
|
|||
}
|
||||
|
||||
unsafe extern "system" fn vulkan_debug_callback(
|
||||
message_severity: vk::DebugUtilsMessageSeverityFlagsEXT,
|
||||
message_type: vk::DebugUtilsMessageTypeFlagsEXT,
|
||||
p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT,
|
||||
_message_severity: vk::DebugUtilsMessageSeverityFlagsEXT,
|
||||
_message_type: vk::DebugUtilsMessageTypeFlagsEXT,
|
||||
_p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT,
|
||||
_user_data: *mut std::os::raw::c_void,
|
||||
) -> vk::Bool32 {
|
||||
// let callback_data = *p_callback_data;
|
||||
|
|
|
@ -29,7 +29,7 @@ pub mod options;
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::filter_chain::FilterChainVulkan;
|
||||
use crate::hello_triangle::vulkan_base::VulkanBase;
|
||||
|
||||
|
@ -38,7 +38,7 @@ mod tests {
|
|||
let entry = unsafe { ash::Entry::load().unwrap() };
|
||||
let base = VulkanBase::new(entry).unwrap();
|
||||
dbg!("finished");
|
||||
let mut filter = FilterChainVulkan::load_from_path(
|
||||
let filter = FilterChainVulkan::load_from_path(
|
||||
&base,
|
||||
// "../test/slang-shaders/border/gameboy-player/gameboy-player-crt-royale.slangp",
|
||||
"../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
|
||||
|
|
|
@ -45,7 +45,7 @@ impl LutTexture {
|
|||
let texture = unsafe { vulkan.device.create_image(&image_info, None)? };
|
||||
|
||||
let memory = unsafe {
|
||||
let mem_reqs = vulkan.device.get_image_memory_requirements(texture.clone());
|
||||
let mem_reqs = vulkan.device.get_image_memory_requirements(texture);
|
||||
let mem_type = util::find_vulkan_memory_type(
|
||||
&vulkan.memory_properties,
|
||||
mem_reqs.memory_type_bits,
|
||||
|
@ -77,7 +77,7 @@ impl LutTexture {
|
|||
let view_info = vk::ImageViewCreateInfo::builder()
|
||||
.view_type(vk::ImageViewType::TYPE_2D)
|
||||
.format(vk::Format::B8G8R8A8_UNORM)
|
||||
.image(texture.clone())
|
||||
.image(texture)
|
||||
.subresource_range(image_subresource)
|
||||
.components(swizzle_components)
|
||||
.build();
|
||||
|
|
|
@ -15,7 +15,7 @@ fn find_graphics_queue_family(
|
|||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
|
||||
pub fn get_graphics_queue(
|
||||
|
|
|
@ -59,7 +59,7 @@ impl OwnedImage {
|
|||
.build();
|
||||
|
||||
let image = unsafe { device.create_image(&image_create_info, None)? };
|
||||
let mem_reqs = unsafe { device.get_image_memory_requirements(image.clone()) };
|
||||
let mem_reqs = unsafe { device.get_image_memory_requirements(image) };
|
||||
|
||||
let alloc_info = vk::MemoryAllocateInfo::builder()
|
||||
.allocation_size(mem_reqs.size)
|
||||
|
@ -92,7 +92,7 @@ impl OwnedImage {
|
|||
let view_info = vk::ImageViewCreateInfo::builder()
|
||||
.view_type(vk::ImageViewType::TYPE_2D)
|
||||
.format(format.into())
|
||||
.image(image.clone())
|
||||
.image(image)
|
||||
.subresource_range(image_subresource)
|
||||
.components(swizzle_components)
|
||||
.build();
|
||||
|
@ -186,7 +186,7 @@ impl OwnedImage {
|
|||
pub(crate) fn as_input(&self, filter: FilterMode, wrap_mode: WrapMode) -> InputImage {
|
||||
InputImage {
|
||||
image: self.image.clone(),
|
||||
image_view: self.image_view.clone(),
|
||||
image_view: self.image_view,
|
||||
wrap_mode,
|
||||
filter_mode: filter,
|
||||
mip_filter: filter,
|
||||
|
@ -530,6 +530,6 @@ pub struct InputImage {
|
|||
|
||||
impl AsRef<InputImage> for InputImage {
|
||||
fn as_ref(&self) -> &InputImage {
|
||||
&self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ pub unsafe fn vulkan_image_layout_transition_levels(
|
|||
barrier.new_layout = new_layout;
|
||||
barrier.src_queue_family_index = src_queue_family_index;
|
||||
barrier.dst_queue_family_index = dst_queue_family_index;
|
||||
barrier.image = image.clone();
|
||||
barrier.image = image;
|
||||
barrier.subresource_range.aspect_mask = vk::ImageAspectFlags::COLOR;
|
||||
barrier.subresource_range.base_array_layer = 0;
|
||||
barrier.subresource_range.level_count = levels;
|
||||
|
|
|
@ -25,7 +25,7 @@ impl VulkanImageMemory {
|
|||
unsafe {
|
||||
Ok(self
|
||||
.device
|
||||
.bind_image_memory(image.clone(), self.handle.clone(), 0)?)
|
||||
.bind_image_memory(*image, self.handle, 0)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ impl VulkanBuffer {
|
|||
.build();
|
||||
|
||||
let alloc = device.allocate_memory(&alloc_info, None)?;
|
||||
device.bind_buffer_memory(buffer.clone(), alloc.clone(), 0)?;
|
||||
device.bind_buffer_memory(buffer, alloc, 0)?;
|
||||
|
||||
Ok(VulkanBuffer {
|
||||
handle: buffer,
|
||||
|
|
|
@ -6,7 +6,7 @@ use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection};
|
|||
use librashader_reflect::reflect::ShaderReflection;
|
||||
use std::ffi::CStr;
|
||||
|
||||
const ENTRY_POINT: &'static CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") };
|
||||
const ENTRY_POINT: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") };
|
||||
|
||||
pub struct PipelineDescriptors {
|
||||
pub replicas: u32,
|
||||
|
@ -138,12 +138,12 @@ impl PipelineLayoutObjects {
|
|||
let descriptor_sets: Vec<vk::DescriptorSet> =
|
||||
descriptor_sets.into_iter().flatten().collect();
|
||||
|
||||
return Ok(PipelineLayoutObjects {
|
||||
Ok(PipelineLayoutObjects {
|
||||
layout,
|
||||
descriptor_set_layout,
|
||||
descriptor_sets,
|
||||
pool,
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ impl VulkanGraphicsPipeline {
|
|||
replicas: u32,
|
||||
) -> error::Result<VulkanGraphicsPipeline> {
|
||||
// shader_vulkan 1927 (init_pipeline_layout)
|
||||
let pipeline_layout = PipelineLayoutObjects::new(&reflection, replicas, device)?;
|
||||
let pipeline_layout = PipelineLayoutObjects::new(reflection, replicas, device)?;
|
||||
|
||||
let input_assembly = vk::PipelineInputAssemblyStateCreateInfo::builder()
|
||||
.topology(vk::PrimitiveTopology::TRIANGLE_STRIP)
|
||||
|
@ -271,13 +271,13 @@ impl VulkanGraphicsPipeline {
|
|||
let shader_stages = [
|
||||
vk::PipelineShaderStageCreateInfo::builder()
|
||||
.stage(vk::ShaderStageFlags::VERTEX)
|
||||
.name(&ENTRY_POINT)
|
||||
.module(vertex_module.shader.clone())
|
||||
.name(ENTRY_POINT)
|
||||
.module(vertex_module.shader)
|
||||
.build(),
|
||||
vk::PipelineShaderStageCreateInfo::builder()
|
||||
.stage(vk::ShaderStageFlags::FRAGMENT)
|
||||
.name(&ENTRY_POINT)
|
||||
.module(fragment_module.shader.clone())
|
||||
.name(ENTRY_POINT)
|
||||
.module(fragment_module.shader)
|
||||
.build(),
|
||||
];
|
||||
|
||||
|
@ -297,7 +297,7 @@ impl VulkanGraphicsPipeline {
|
|||
let pipeline = unsafe {
|
||||
// panic_safety: if this is successful this should return 1 pipelines.
|
||||
device
|
||||
.create_graphics_pipelines(cache.clone(), &[pipeline_info], None)
|
||||
.create_graphics_pipelines(*cache, &[pipeline_info], None)
|
||||
.map_err(|e| e.1)
|
||||
.unwrap()[0]
|
||||
};
|
||||
|
|
|
@ -79,7 +79,7 @@ where
|
|||
device: &Self::DeviceContext,
|
||||
);
|
||||
|
||||
#[clippy::allow(too_many_arguments)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
/// Write uniform and texture semantics to the provided storages.
|
||||
fn bind_semantics<'a>(
|
||||
device: &Self::DeviceContext,
|
||||
|
|
Loading…
Reference in a new issue