fmt: run clippy and rustfmt
This commit is contained in:
parent
dffea95370
commit
8b6481abc1
|
@ -27,13 +27,30 @@
|
||||||
//! ## Booleans
|
//! ## Booleans
|
||||||
//! Some option structs take `bool` values.
|
//! Some option structs take `bool` values.
|
||||||
//! Any booleans passed to librashader **must have a bit pattern equivalent to either `1` or `0`**. Any other value will cause
|
//! Any booleans passed to librashader **must have a bit pattern equivalent to either `1` or `0`**. Any other value will cause
|
||||||
//! **immediate undefined behaviour**.
|
//! **immediate undefined behaviour**. Using `_Bool` from `stdbool.h` should maintain this invariant.
|
||||||
//!
|
//!
|
||||||
//! ## Errors
|
//! ## Errors
|
||||||
//! The librashader C API provides a robust, reflective error system. Every function returns a `libra_error_t`, which is either
|
//! The librashader C API provides a robust, reflective error system. Every function returns a `libra_error_t`, which is either
|
||||||
//! a null pointer, or a handle to an opaque allocated error object. If the returned error is null, then the function was successful.
|
//! a null pointer, or a handle to an opaque allocated error object. If the returned error is null, then the function was successful.
|
||||||
//! Otherwise, error information can be accessed via the `libra_error_` set of APIs. If an error indeed occurs, it may be freed by
|
//! Otherwise, error information can be accessed via the `libra_error_` set of APIs. If an error indeed occurs, it may be freed by
|
||||||
//! `libra_error_free`.
|
//! `libra_error_free`.
|
||||||
|
//!
|
||||||
|
//! It is **highly recommended** to check for errors after every call to a librashader API like in the following example.
|
||||||
|
//!
|
||||||
|
//! ```c
|
||||||
|
//! libra_preset_t preset;
|
||||||
|
//! libra_error_t error = libra.preset_create(
|
||||||
|
//! "slang-shaders/crt/crt-lottes.slangp", &preset);
|
||||||
|
//! if (error != NULL) {
|
||||||
|
//! libra.error_print(error);
|
||||||
|
//! libra.error_free(&error);
|
||||||
|
//! exit(1);
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! There is a case to be made for skipping error checking for `*_filter_chain_frame` due to performance reasons,
|
||||||
|
//! but only if you are certain that the safety invariants are upheld on each call. Failure to check for errors
|
||||||
|
//! may result in **undefined behaviour** stemming from failure to uphold safety invariants.
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![feature(pointer_is_aligned)]
|
#![feature(pointer_is_aligned)]
|
||||||
|
|
|
@ -12,7 +12,9 @@ pub enum PreprocessError {
|
||||||
#[error("the file was not found during resolution")]
|
#[error("the file was not found during resolution")]
|
||||||
IOError(PathBuf, std::io::Error),
|
IOError(PathBuf, std::io::Error),
|
||||||
/// A known encoding was not found for the file.
|
/// A known encoding was not found for the file.
|
||||||
#[error("a known encoding was not found for the file. supported encodings are UTF-8 and Latin-1")]
|
#[error(
|
||||||
|
"a known encoding was not found for the file. supported encodings are UTF-8 and Latin-1"
|
||||||
|
)]
|
||||||
EncodingError(PathBuf),
|
EncodingError(PathBuf),
|
||||||
/// Unexpected EOF when reading the source file.
|
/// Unexpected EOF when reading the source file.
|
||||||
#[error("unexpected end of file")]
|
#[error("unexpected end of file")]
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::{PreprocessError, SourceOutput};
|
use crate::{PreprocessError, SourceOutput};
|
||||||
|
use encoding_rs::{DecoderResult, WINDOWS_1252};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::str::Lines;
|
use std::str::Lines;
|
||||||
use encoding_rs::{DecoderResult, WINDOWS_1252};
|
|
||||||
|
|
||||||
#[cfg(feature = "line_directives")]
|
#[cfg(feature = "line_directives")]
|
||||||
const GL_GOOGLE_CPP_STYLE_LINE_DIRECTIVE: &str =
|
const GL_GOOGLE_CPP_STYLE_LINE_DIRECTIVE: &str =
|
||||||
|
@ -30,7 +30,8 @@ fn read_file(path: impl AsRef<Path>) -> Result<String, PreprocessError> {
|
||||||
|
|
||||||
let mut latin1_string = String::with_capacity(len);
|
let mut latin1_string = String::with_capacity(len);
|
||||||
|
|
||||||
let (result, _) = WINDOWS_1252.new_decoder()
|
let (result, _) = WINDOWS_1252
|
||||||
|
.new_decoder()
|
||||||
.decode_to_string_without_replacement(&buf, &mut latin1_string, true);
|
.decode_to_string_without_replacement(&buf, &mut latin1_string, true);
|
||||||
if result == DecoderResult::InputEmpty {
|
if result == DecoderResult::InputEmpty {
|
||||||
Ok(latin1_string)
|
Ok(latin1_string)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::reflect::semantics::{MemberOffset, UniformMemberBlock};
|
use crate::reflect::semantics::UniformMemberBlock;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
/// Error type for shader compilation.
|
/// Error type for shader compilation.
|
||||||
|
@ -82,7 +82,7 @@ pub enum ShaderReflectError {
|
||||||
expected: usize,
|
expected: usize,
|
||||||
received: usize,
|
received: usize,
|
||||||
ty: UniformMemberBlock,
|
ty: UniformMemberBlock,
|
||||||
pass: usize
|
pass: usize,
|
||||||
},
|
},
|
||||||
/// The size of the given uniform did not match up in both the vertex and fragment shader.
|
/// The size of the given uniform did not match up in both the vertex and fragment shader.
|
||||||
#[error("mismatched component")]
|
#[error("mismatched component")]
|
||||||
|
@ -90,7 +90,7 @@ pub enum ShaderReflectError {
|
||||||
semantic: String,
|
semantic: String,
|
||||||
vertex: u32,
|
vertex: u32,
|
||||||
fragment: u32,
|
fragment: u32,
|
||||||
pass: usize
|
pass: usize,
|
||||||
},
|
},
|
||||||
/// The binding number is already in use.
|
/// The binding number is already in use.
|
||||||
#[error("the binding is already in use")]
|
#[error("the binding is already in use")]
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
|
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
|
||||||
use crate::front::GlslangCompilation;
|
use crate::front::GlslangCompilation;
|
||||||
use crate::reflect::semantics::{BindingMeta, BindingStage, MemberOffset, PushReflection, ShaderReflection, ShaderSemantics, TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UboReflection, UniqueSemanticMap, UniqueSemantics, ValidateTypeSemantics, VariableMeta, MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE, UniformMemberBlock};
|
use crate::reflect::semantics::{
|
||||||
|
BindingMeta, BindingStage, MemberOffset, PushReflection, ShaderReflection, ShaderSemantics,
|
||||||
|
TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UboReflection,
|
||||||
|
UniformMemberBlock, UniqueSemanticMap, UniqueSemantics, ValidateTypeSemantics, VariableMeta,
|
||||||
|
MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE,
|
||||||
|
};
|
||||||
use crate::reflect::{align_uniform_size, ReflectShader};
|
use crate::reflect::{align_uniform_size, ReflectShader};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
@ -311,7 +316,7 @@ where
|
||||||
semantic: name,
|
semantic: name,
|
||||||
vertex: meta.size,
|
vertex: meta.size,
|
||||||
fragment: typeinfo.size,
|
fragment: typeinfo.size,
|
||||||
pass: pass_number
|
pass: pass_number,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +351,7 @@ where
|
||||||
semantic: name,
|
semantic: name,
|
||||||
vertex: meta.size,
|
vertex: meta.size,
|
||||||
fragment: typeinfo.size,
|
fragment: typeinfo.size,
|
||||||
pass: pass_number
|
pass: pass_number,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -851,7 +856,7 @@ mod test {
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use crate::back::CompileShader;
|
use crate::back::CompileShader;
|
||||||
use crate::front::shaderc::GlslangCompilation;
|
use crate::front::GlslangCompilation;
|
||||||
use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics};
|
use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics};
|
||||||
use librashader_preprocess::ShaderSource;
|
use librashader_preprocess::ShaderSource;
|
||||||
use spirv_cross::glsl;
|
use spirv_cross::glsl;
|
||||||
|
|
|
@ -201,50 +201,46 @@ pub struct MemberOffset {
|
||||||
pub push: Option<usize>,
|
pub push: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
/// The block where a uniform member is located.
|
/// The block where a uniform member is located.
|
||||||
pub enum UniformMemberBlock {
|
pub enum UniformMemberBlock {
|
||||||
/// The offset is for a UBO.
|
/// The offset is for a UBO.
|
||||||
Ubo,
|
Ubo,
|
||||||
/// The offset is for a push constant block.
|
/// The offset is for a push constant block.
|
||||||
PushConstant
|
PushConstant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UniformMemberBlock {
|
impl UniformMemberBlock {
|
||||||
/// A list of valid member block types.
|
/// A list of valid member block types.
|
||||||
pub const TYPES: [UniformMemberBlock; 2] = [UniformMemberBlock::Ubo, UniformMemberBlock::PushConstant];
|
pub const TYPES: [UniformMemberBlock; 2] =
|
||||||
|
[UniformMemberBlock::Ubo, UniformMemberBlock::PushConstant];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemberOffset {
|
impl MemberOffset {
|
||||||
pub(crate) fn new(off: usize, ty: UniformMemberBlock) -> Self {
|
pub(crate) fn new(off: usize, ty: UniformMemberBlock) -> Self {
|
||||||
match ty {
|
match ty {
|
||||||
UniformMemberBlock::Ubo => {
|
UniformMemberBlock::Ubo => MemberOffset {
|
||||||
MemberOffset {
|
|
||||||
ubo: Some(off),
|
ubo: Some(off),
|
||||||
push: None,
|
push: None,
|
||||||
}
|
},
|
||||||
}
|
UniformMemberBlock::PushConstant => MemberOffset {
|
||||||
UniformMemberBlock::PushConstant => {
|
|
||||||
MemberOffset {
|
|
||||||
ubo: None,
|
ubo: None,
|
||||||
push: Some(off),
|
push: Some(off),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn offset(&self, ty: UniformMemberBlock) -> Option<usize> {
|
pub fn offset(&self, ty: UniformMemberBlock) -> Option<usize> {
|
||||||
match ty {
|
match ty {
|
||||||
UniformMemberBlock::Ubo => {self.ubo}
|
UniformMemberBlock::Ubo => self.ubo,
|
||||||
UniformMemberBlock::PushConstant => {self.push}
|
UniformMemberBlock::PushConstant => self.push,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn offset_mut(&mut self, ty: UniformMemberBlock) -> &mut Option<usize> {
|
pub(crate) fn offset_mut(&mut self, ty: UniformMemberBlock) -> &mut Option<usize> {
|
||||||
match ty {
|
match ty {
|
||||||
UniformMemberBlock::Ubo => {&mut self.ubo}
|
UniformMemberBlock::Ubo => &mut self.ubo,
|
||||||
UniformMemberBlock::PushConstant => {&mut self.push}
|
UniformMemberBlock::PushConstant => &mut self.push,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,7 +411,7 @@ pub mod d3d11_hello_triangle {
|
||||||
.ClearRenderTargetView(&resources.backbuffer_rtv, color.as_ptr());
|
.ClearRenderTargetView(&resources.backbuffer_rtv, color.as_ptr());
|
||||||
self.context.ClearDepthStencilView(
|
self.context.ClearDepthStencilView(
|
||||||
&resources.depth_stencil_view,
|
&resources.depth_stencil_view,
|
||||||
D3D11_CLEAR_DEPTH.0 as u32,
|
D3D11_CLEAR_DEPTH.0,
|
||||||
1.0,
|
1.0,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
|
@ -33,8 +33,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn triangle_d3d11() {
|
fn triangle_d3d11() {
|
||||||
let sample = hello_triangle::d3d11_hello_triangle::Sample::new(
|
let sample = hello_triangle::d3d11_hello_triangle::Sample::new(
|
||||||
// "../test/slang-shaders/presets/crt-royale-kurozumi.slangp",
|
"../test/slang-shaders/crt/crt-royale.slangp",
|
||||||
"../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
|
|
||||||
// "../test/basic.slangp",
|
// "../test/basic.slangp",
|
||||||
Some(&FilterChainOptionsD3D11 {
|
Some(&FilterChainOptionsD3D11 {
|
||||||
use_deferred_context: false,
|
use_deferred_context: false,
|
||||||
|
|
|
@ -2,7 +2,9 @@ use crate::error;
|
||||||
use crate::error::assume_d3d11_init;
|
use crate::error::assume_d3d11_init;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use windows::core::PCSTR;
|
use windows::core::PCSTR;
|
||||||
use windows::Win32::Graphics::Direct3D::Fxc::{D3DCompile, D3DCOMPILE_DEBUG, D3DCOMPILE_OPTIMIZATION_LEVEL3, D3DCOMPILE_SKIP_OPTIMIZATION};
|
use windows::Win32::Graphics::Direct3D::Fxc::{
|
||||||
|
D3DCompile, D3DCOMPILE_DEBUG, D3DCOMPILE_OPTIMIZATION_LEVEL3, D3DCOMPILE_SKIP_OPTIMIZATION,
|
||||||
|
};
|
||||||
use windows::Win32::Graphics::Direct3D::ID3DBlob;
|
use windows::Win32::Graphics::Direct3D::ID3DBlob;
|
||||||
use windows::Win32::Graphics::Direct3D11::*;
|
use windows::Win32::Graphics::Direct3D11::*;
|
||||||
use windows::Win32::Graphics::Dxgi::Common::*;
|
use windows::Win32::Graphics::Dxgi::Common::*;
|
||||||
|
|
|
@ -10,26 +10,10 @@ pub struct VariableLocation {
|
||||||
|
|
||||||
impl VariableLocation {
|
impl VariableLocation {
|
||||||
pub fn location(&self, offset_type: UniformMemberBlock) -> Option<UniformLocation<GLint>> {
|
pub fn location(&self, offset_type: UniformMemberBlock) -> Option<UniformLocation<GLint>> {
|
||||||
let value = match offset_type {
|
match offset_type {
|
||||||
UniformMemberBlock::Ubo => {
|
UniformMemberBlock::Ubo => self.ubo,
|
||||||
self.ubo
|
UniformMemberBlock::PushConstant => self.push,
|
||||||
}
|
}
|
||||||
UniformMemberBlock::PushConstant => {
|
|
||||||
self.push
|
|
||||||
}
|
|
||||||
};
|
|
||||||
value
|
|
||||||
}
|
|
||||||
pub fn is_valid(&self, offset_type: UniformMemberBlock, stage: BindingStage) -> bool {
|
|
||||||
let value = self.location(offset_type);
|
|
||||||
let mut validity = false;
|
|
||||||
if stage.contains(BindingStage::FRAGMENT) {
|
|
||||||
validity = validity || value.is_some_and(|f| f.fragment >= 0);
|
|
||||||
}
|
|
||||||
if stage.contains(BindingStage::VERTEX) {
|
|
||||||
validity = validity || value.is_some_and(|f| f.vertex >= 0);
|
|
||||||
}
|
|
||||||
validity
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +81,11 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BindUniform<VariableLocation, &[f32; 4]> for GlUniformBinder {
|
impl BindUniform<VariableLocation, &[f32; 4]> for GlUniformBinder {
|
||||||
fn bind_uniform(block: UniformMemberBlock, vec4: &[f32; 4], location: VariableLocation) -> Option<()> {
|
fn bind_uniform(
|
||||||
|
block: UniformMemberBlock,
|
||||||
|
vec4: &[f32; 4],
|
||||||
|
location: VariableLocation,
|
||||||
|
) -> Option<()> {
|
||||||
if let Some(location) = location.location(block)
|
if let Some(location) = location.location(block)
|
||||||
&& location.bindable()
|
&& location.bindable()
|
||||||
{
|
{
|
||||||
|
@ -117,7 +105,11 @@ impl BindUniform<VariableLocation, &[f32; 4]> for GlUniformBinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BindUniform<VariableLocation, &[f32; 16]> for GlUniformBinder {
|
impl BindUniform<VariableLocation, &[f32; 16]> for GlUniformBinder {
|
||||||
fn bind_uniform(block: UniformMemberBlock, mat4: &[f32; 16], location: VariableLocation) -> Option<()> {
|
fn bind_uniform(
|
||||||
|
block: UniformMemberBlock,
|
||||||
|
mat4: &[f32; 16],
|
||||||
|
location: VariableLocation,
|
||||||
|
) -> Option<()> {
|
||||||
if let Some(location) = location.location(block)
|
if let Some(location) = location.location(block)
|
||||||
&& location.bindable()
|
&& location.bindable()
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,7 @@ use librashader_reflect::back::targets::GLSL;
|
||||||
use librashader_reflect::back::{CompileReflectShader, CompileShader};
|
use librashader_reflect::back::{CompileReflectShader, CompileShader};
|
||||||
use librashader_reflect::front::GlslangCompilation;
|
use librashader_reflect::front::GlslangCompilation;
|
||||||
use librashader_reflect::reflect::semantics::{
|
use librashader_reflect::reflect::semantics::{
|
||||||
MemberOffset, ShaderSemantics, TextureSemantics, UniformBinding, UniformMeta,
|
ShaderSemantics, TextureSemantics, UniformBinding, UniformMeta,
|
||||||
};
|
};
|
||||||
|
|
||||||
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
|
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
|
||||||
|
@ -53,7 +53,6 @@ pub struct FilterMutable {
|
||||||
|
|
||||||
impl<T: GLInterface> FilterChainImpl<T> {
|
impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
fn reflect_uniform_location(pipeline: GLuint, meta: &impl UniformMeta) -> VariableLocation {
|
fn reflect_uniform_location(pipeline: GLuint, meta: &impl UniformMeta) -> VariableLocation {
|
||||||
|
|
||||||
let mut location = VariableLocation {
|
let mut location = VariableLocation {
|
||||||
ubo: None,
|
ubo: None,
|
||||||
push: None,
|
push: None,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use gl::types::{GLint, GLsizei, GLuint};
|
use gl::types::{GLsizei, GLuint};
|
||||||
use librashader_reflect::back::cross::CrossGlslContext;
|
use librashader_reflect::back::cross::CrossGlslContext;
|
||||||
use librashader_reflect::back::ShaderCompilerOutput;
|
use librashader_reflect::back::ShaderCompilerOutput;
|
||||||
use librashader_reflect::reflect::ShaderReflection;
|
use librashader_reflect::reflect::ShaderReflection;
|
||||||
|
|
|
@ -149,7 +149,7 @@ struct FrameResiduals {
|
||||||
device: ash::Device,
|
device: ash::Device,
|
||||||
image_views: Vec<vk::ImageView>,
|
image_views: Vec<vk::ImageView>,
|
||||||
owned: Vec<OwnedImage>,
|
owned: Vec<OwnedImage>,
|
||||||
framebuffers: Vec<Option<vk::Framebuffer>>
|
framebuffers: Vec<Option<vk::Framebuffer>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FrameResiduals {
|
impl FrameResiduals {
|
||||||
|
@ -232,8 +232,15 @@ impl FilterChainVulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize passes
|
// initialize passes
|
||||||
let filters = Self::init_passes(&device, passes, &semantics, frames_in_flight, options
|
let filters = Self::init_passes(
|
||||||
.map(|o| o.render_pass_format).unwrap_or(vk::Format::UNDEFINED))?;
|
&device,
|
||||||
|
passes,
|
||||||
|
&semantics,
|
||||||
|
frames_in_flight,
|
||||||
|
options
|
||||||
|
.map(|o| o.render_pass_format)
|
||||||
|
.unwrap_or(vk::Format::UNDEFINED),
|
||||||
|
)?;
|
||||||
|
|
||||||
let luts = FilterChainVulkan::load_luts(&device, &preset.textures)?;
|
let luts = FilterChainVulkan::load_luts(&device, &preset.textures)?;
|
||||||
let samplers = SamplerSet::new(&device.device)?;
|
let samplers = SamplerSet::new(&device.device)?;
|
||||||
|
@ -348,7 +355,7 @@ impl FilterChainVulkan {
|
||||||
&spirv_words,
|
&spirv_words,
|
||||||
&reflection,
|
&reflection,
|
||||||
frames_in_flight,
|
frames_in_flight,
|
||||||
render_pass_format
|
render_pass_format,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// let ubo_ring = VkUboRing::new(
|
// let ubo_ring = VkUboRing::new(
|
||||||
|
|
|
@ -132,7 +132,9 @@ impl FilterPass {
|
||||||
|
|
||||||
output.output.begin_pass(cmd);
|
output.output.begin_pass(cmd);
|
||||||
|
|
||||||
let residual = self.graphics_pipeline.begin_rendering(&parent.device, output, cmd)?;
|
let residual = self
|
||||||
|
.graphics_pipeline
|
||||||
|
.begin_rendering(&parent.device, output, cmd)?;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
parent.device.cmd_bind_pipeline(
|
parent.device.cmd_bind_pipeline(
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ash::vk;
|
||||||
|
|
||||||
use crate::error::FilterChainError;
|
use crate::error::FilterChainError;
|
||||||
use crate::filter_chain::VulkanObjects;
|
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::physicaldevice::{find_queue_family, pick_physical_device};
|
||||||
|
|
||||||
use ash::prelude::VkResult;
|
use ash::prelude::VkResult;
|
||||||
|
@ -76,7 +76,7 @@ impl VulkanBase {
|
||||||
instance: &ash::Instance,
|
instance: &ash::Instance,
|
||||||
physical_device: &vk::PhysicalDevice,
|
physical_device: &vk::PhysicalDevice,
|
||||||
) -> VkResult<(ash::Device, vk::Queue)> {
|
) -> VkResult<(ash::Device, vk::Queue)> {
|
||||||
let debug = [unsafe { CStr::from_bytes_with_nul_unchecked(KHRONOS_VALIDATION).as_ptr() }];
|
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()
|
let queue_info = [vk::DeviceQueueCreateInfo::builder()
|
||||||
|
|
|
@ -34,10 +34,10 @@ mod render_pass;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ash::vk;
|
|
||||||
use crate::filter_chain::FilterChainVulkan;
|
use crate::filter_chain::FilterChainVulkan;
|
||||||
use crate::hello_triangle::vulkan_base::VulkanBase;
|
use crate::hello_triangle::vulkan_base::VulkanBase;
|
||||||
use crate::options::FilterChainOptionsVulkan;
|
use crate::options::FilterChainOptionsVulkan;
|
||||||
|
use ash::vk;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn triangle_vk() {
|
fn triangle_vk() {
|
||||||
|
|
|
@ -24,5 +24,5 @@ pub struct FilterChainOptionsVulkan {
|
||||||
/// will be used instead of a render pass. If this is set to some format, the render passes
|
/// will be used instead of a render pass. If this is set to some format, the render passes
|
||||||
/// will be created with such format. It is recommended if possible to use dynamic rendering,
|
/// will be created with such format. It is recommended if possible to use dynamic rendering,
|
||||||
/// because render-pass mode will create new framebuffers per pass.
|
/// because render-pass mode will create new framebuffers per pass.
|
||||||
pub render_pass_format: vk::Format
|
pub render_pass_format: vk::Format,
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,7 @@ pub struct VulkanRenderPass {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VulkanRenderPass {
|
impl VulkanRenderPass {
|
||||||
pub fn create_render_pass(
|
pub fn create_render_pass(device: &ash::Device, format: vk::Format) -> error::Result<Self> {
|
||||||
device: &ash::Device,
|
|
||||||
mut format: vk::Format,
|
|
||||||
) -> error::Result<Self> {
|
|
||||||
// format should never be undefined.
|
// format should never be undefined.
|
||||||
let attachment = [vk::AttachmentDescription::builder()
|
let attachment = [vk::AttachmentDescription::builder()
|
||||||
.flags(vk::AttachmentDescriptionFlags::empty())
|
.flags(vk::AttachmentDescriptionFlags::empty())
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
use crate::{error, util};
|
use crate::{error, util};
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
|
|
||||||
|
use crate::render_pass::VulkanRenderPass;
|
||||||
|
use crate::render_target::RenderTarget;
|
||||||
use librashader_reflect::back::ShaderCompilerOutput;
|
use librashader_reflect::back::ShaderCompilerOutput;
|
||||||
use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection};
|
use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection};
|
||||||
use librashader_reflect::reflect::ShaderReflection;
|
use librashader_reflect::reflect::ShaderReflection;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use crate::framebuffer::OutputImage;
|
|
||||||
use crate::render_target::RenderTarget;
|
|
||||||
use crate::render_pass::VulkanRenderPass;
|
|
||||||
|
|
||||||
|
|
||||||
const ENTRY_POINT: &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") };
|
||||||
|
|
||||||
|
@ -177,7 +175,7 @@ impl Drop for VulkanShaderModule {
|
||||||
pub struct VulkanGraphicsPipeline {
|
pub struct VulkanGraphicsPipeline {
|
||||||
pub layout: PipelineLayoutObjects,
|
pub layout: PipelineLayoutObjects,
|
||||||
pub pipeline: vk::Pipeline,
|
pub pipeline: vk::Pipeline,
|
||||||
pub render_pass: Option<VulkanRenderPass>
|
pub render_pass: Option<VulkanRenderPass>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VulkanGraphicsPipeline {
|
impl VulkanGraphicsPipeline {
|
||||||
|
@ -187,7 +185,7 @@ impl VulkanGraphicsPipeline {
|
||||||
shader_assembly: &ShaderCompilerOutput<Vec<u32>>,
|
shader_assembly: &ShaderCompilerOutput<Vec<u32>>,
|
||||||
reflection: &ShaderReflection,
|
reflection: &ShaderReflection,
|
||||||
replicas: u32,
|
replicas: u32,
|
||||||
render_pass_format: vk::Format
|
render_pass_format: vk::Format,
|
||||||
) -> error::Result<VulkanGraphicsPipeline> {
|
) -> error::Result<VulkanGraphicsPipeline> {
|
||||||
let pipeline_layout = PipelineLayoutObjects::new(reflection, replicas, device)?;
|
let pipeline_layout = PipelineLayoutObjects::new(reflection, replicas, device)?;
|
||||||
|
|
||||||
|
@ -300,7 +298,10 @@ impl VulkanGraphicsPipeline {
|
||||||
|
|
||||||
let mut render_pass = None;
|
let mut render_pass = None;
|
||||||
if render_pass_format != vk::Format::UNDEFINED {
|
if render_pass_format != vk::Format::UNDEFINED {
|
||||||
render_pass = Some(VulkanRenderPass::create_render_pass(&device, render_pass_format)?);
|
render_pass = Some(VulkanRenderPass::create_render_pass(
|
||||||
|
device,
|
||||||
|
render_pass_format,
|
||||||
|
)?);
|
||||||
pipeline_info = pipeline_info.render_pass(render_pass.as_ref().unwrap().handle)
|
pipeline_info = pipeline_info.render_pass(render_pass.as_ref().unwrap().handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +323,12 @@ impl VulkanGraphicsPipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn begin_rendering(&self, device: &ash::Device, output: &RenderTarget, cmd: vk::CommandBuffer) -> error::Result<Option<vk::Framebuffer>>{
|
pub(crate) fn begin_rendering(
|
||||||
|
&self,
|
||||||
|
device: &ash::Device,
|
||||||
|
output: &RenderTarget,
|
||||||
|
cmd: vk::CommandBuffer,
|
||||||
|
) -> error::Result<Option<vk::Framebuffer>> {
|
||||||
if let Some(render_pass) = &self.render_pass {
|
if let Some(render_pass) = &self.render_pass {
|
||||||
let attachments = [output.output.image_view];
|
let attachments = [output.output.image_view];
|
||||||
let framebuffer = unsafe {
|
let framebuffer = unsafe {
|
||||||
|
@ -340,8 +346,8 @@ impl VulkanGraphicsPipeline {
|
||||||
|
|
||||||
let clear_values = [vk::ClearValue {
|
let clear_values = [vk::ClearValue {
|
||||||
color: vk::ClearColorValue {
|
color: vk::ClearColorValue {
|
||||||
float32: [0.0, 0.0, 0.0, 0.0]
|
float32: [0.0, 0.0, 0.0, 0.0],
|
||||||
}
|
},
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let render_pass_info = vk::RenderPassBeginInfo::builder()
|
let render_pass_info = vk::RenderPassBeginInfo::builder()
|
||||||
|
@ -350,12 +356,10 @@ impl VulkanGraphicsPipeline {
|
||||||
.clear_values(&clear_values)
|
.clear_values(&clear_values)
|
||||||
// always render into the full output, regardless of viewport settings.
|
// always render into the full output, regardless of viewport settings.
|
||||||
.render_area(vk::Rect2D {
|
.render_area(vk::Rect2D {
|
||||||
offset: vk::Offset2D {
|
offset: vk::Offset2D { x: 0, y: 0 },
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
},
|
|
||||||
extent: output.output.size.into(),
|
extent: output.output.size.into(),
|
||||||
}).build();
|
})
|
||||||
|
.build();
|
||||||
unsafe {
|
unsafe {
|
||||||
device.cmd_begin_render_pass(cmd, &render_pass_info, vk::SubpassContents::INLINE);
|
device.cmd_begin_render_pass(cmd, &render_pass_info, vk::SubpassContents::INLINE);
|
||||||
}
|
}
|
||||||
|
@ -382,7 +386,6 @@ impl VulkanGraphicsPipeline {
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn end_rendering(&self, device: &ash::Device, cmd: vk::CommandBuffer) {
|
pub(crate) fn end_rendering(&self, device: &ash::Device, cmd: vk::CommandBuffer) {
|
||||||
|
|
|
@ -89,12 +89,8 @@ where
|
||||||
|
|
||||||
pub(crate) fn buffer(&mut self, ty: UniformMemberBlock) -> &mut [u8] {
|
pub(crate) fn buffer(&mut self, ty: UniformMemberBlock) -> &mut [u8] {
|
||||||
match ty {
|
match ty {
|
||||||
UniformMemberBlock::Ubo => {
|
UniformMemberBlock::Ubo => self.ubo.deref_mut(),
|
||||||
self.ubo.deref_mut()
|
UniformMemberBlock::PushConstant => self.push.deref_mut(),
|
||||||
}
|
|
||||||
UniformMemberBlock::PushConstant => {
|
|
||||||
self.push.deref_mut()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,8 +101,7 @@ where
|
||||||
S: Deref<Target = [u8]> + DerefMut,
|
S: Deref<Target = [u8]> + DerefMut,
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn write_scalar_inner<T: UniformScalar>(buffer: &mut [u8], value: T)
|
fn write_scalar_inner<T: UniformScalar>(buffer: &mut [u8], value: T) {
|
||||||
{
|
|
||||||
let buffer = bytemuck::cast_slice_mut(buffer);
|
let buffer = bytemuck::cast_slice_mut(buffer);
|
||||||
buffer[0] = value;
|
buffer[0] = value;
|
||||||
}
|
}
|
||||||
|
@ -124,10 +119,7 @@ where
|
||||||
|
|
||||||
if let Some(offset) = offset.offset(ty) {
|
if let Some(offset) = offset.offset(ty) {
|
||||||
let buffer = self.buffer(ty);
|
let buffer = self.buffer(ty);
|
||||||
Self::write_scalar_inner(
|
Self::write_scalar_inner(&mut buffer[offset..][..std::mem::size_of::<T>()], value)
|
||||||
&mut buffer[offset..][..std::mem::size_of::<T>()],
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +163,6 @@ where
|
||||||
pub fn bind_vec4(&mut self, offset: MemberOffset, value: impl Into<[f32; 4]>, ctx: C) {
|
pub fn bind_vec4(&mut self, offset: MemberOffset, value: impl Into<[f32; 4]>, ctx: C) {
|
||||||
let vec4 = value.into();
|
let vec4 = value.into();
|
||||||
|
|
||||||
|
|
||||||
for ty in UniformMemberBlock::TYPES {
|
for ty in UniformMemberBlock::TYPES {
|
||||||
if H::bind_uniform(ty, &vec4, ctx).is_some() {
|
if H::bind_uniform(ty, &vec4, ctx).is_some() {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue