diff --git a/librashader-reflect/src/reflect/uniforms.rs b/librashader-reflect/src/reflect/uniforms.rs index 6e6d2f3..fdc945d 100644 --- a/librashader-reflect/src/reflect/uniforms.rs +++ b/librashader-reflect/src/reflect/uniforms.rs @@ -17,20 +17,20 @@ pub trait BindUniform { fn bind_uniform(value: T, ctx: C) -> Option<()>; } -pub struct UniformBuffer> { +pub struct UniformStorage> { pub ubo: Box<[u8]>, pub push: Box<[u8]>, _h: PhantomData, _c: PhantomData } -impl UniformBuffer +impl UniformStorage where H: BindUniform, H: BindUniform, H: BindUniform, H: for <'a> BindUniform, H: for <'a> BindUniform { pub fn new(ubo_size: usize, push_size: usize) -> Self { - UniformBuffer { + UniformStorage { ubo: vec![0u8; ubo_size].into_boxed_slice(), push: vec![0u8; push_size].into_boxed_slice(), _h: Default::default(), @@ -63,15 +63,12 @@ H: for <'a> BindUniform } } - pub fn bind_mat4(&mut self, offset: MemberOffset, value: &[f32; 16], ctx: C) { let (buffer, offset) = match offset { MemberOffset::Ubo(offset) => (&mut self.ubo, offset), MemberOffset::PushConstant(offset) => (&mut self.push, offset), }; - let size = value.len() * std::mem::size_of::(); - - Self::write_mat4_inner(&mut buffer[offset..][..size], value, ctx); + Self::write_mat4_inner(&mut buffer[offset..][..16 * std::mem::size_of::()], value, ctx); } pub fn bind_vec4(&mut self, offset: MemberOffset, value: impl Into<[f32; 4]>, ctx: C) { @@ -80,7 +77,7 @@ H: for <'a> BindUniform MemberOffset::PushConstant(offset) => (&mut self.push, offset), }; - Self::write_vec4_inner(&mut buffer[offset..][..16], value, ctx); + Self::write_vec4_inner(&mut buffer[offset..][..4 * std::mem::size_of::()], value, ctx); } pub fn bind_scalar(&mut self, offset: MemberOffset, value: T, ctx: C) @@ -91,6 +88,6 @@ H: for <'a> BindUniform MemberOffset::PushConstant(offset) => (&mut self.push, offset), }; - Self::write_scalar_inner(&mut buffer[offset..][..4], value, ctx) + Self::write_scalar_inner(&mut buffer[offset..][..std::mem::size_of::()], value, ctx) } } \ No newline at end of file diff --git a/librashader-runtime-gl/src/binding.rs b/librashader-runtime-gl/src/binding.rs index 1ecd529..fa55290 100644 --- a/librashader-runtime-gl/src/binding.rs +++ b/librashader-runtime-gl/src/binding.rs @@ -1,6 +1,6 @@ use gl::types::GLint; use librashader_reflect::reflect::semantics::BindingStage; -use librashader_reflect::reflect::uniforms::{BindUniform, UniformBuffer, UniformScalar}; +use librashader_reflect::reflect::uniforms::{BindUniform, UniformStorage, UniformScalar}; #[derive(Debug)] pub enum VariableLocation { @@ -35,7 +35,7 @@ impl UniformLocation { } } -pub(crate) type BufferStorage = UniformBuffer>; +pub(crate) type BufferStorage = UniformStorage>; pub trait GlUniformScalar: UniformScalar { diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index a6366d2..96ca8c6 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -8,7 +8,7 @@ use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; use librashader_reflect::reflect::semantics::{BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, VariableSemantics}; use rustc_hash::FxHashMap; -use librashader_reflect::reflect::uniforms::UniformBuffer; +use librashader_reflect::reflect::uniforms::UniformStorage; use crate::binding::{BufferStorage, GlUniformBinder, UniformLocation, VariableLocation}; use crate::filter_chain::FilterCommon; diff --git a/librashader-runtime-gl/src/util.rs b/librashader-runtime-gl/src/util.rs index 45b28a7..dfaf139 100644 --- a/librashader-runtime-gl/src/util.rs +++ b/librashader-runtime-gl/src/util.rs @@ -2,7 +2,7 @@ use gl::types::{GLenum, GLint, GLuint}; use librashader_common::Size; use librashader_reflect::back::cross::GlVersion; use librashader_reflect::reflect::semantics::BindingStage; -use librashader_reflect::reflect::uniforms::{BindUniform, UniformBuffer, UniformScalar}; +use librashader_reflect::reflect::uniforms::{BindUniform, UniformStorage, UniformScalar}; use crate::binding::UniformLocation; pub fn calc_miplevel(size: Size) -> u32 { diff --git a/librashader-runtime-gl46/src/binding.rs b/librashader-runtime-gl46/src/binding.rs index 1ecd529..fa55290 100644 --- a/librashader-runtime-gl46/src/binding.rs +++ b/librashader-runtime-gl46/src/binding.rs @@ -1,6 +1,6 @@ use gl::types::GLint; use librashader_reflect::reflect::semantics::BindingStage; -use librashader_reflect::reflect::uniforms::{BindUniform, UniformBuffer, UniformScalar}; +use librashader_reflect::reflect::uniforms::{BindUniform, UniformStorage, UniformScalar}; #[derive(Debug)] pub enum VariableLocation { @@ -35,7 +35,7 @@ impl UniformLocation { } } -pub(crate) type BufferStorage = UniformBuffer>; +pub(crate) type BufferStorage = UniformStorage>; pub trait GlUniformScalar: UniformScalar {