gl: fix vec4 buffer length
This commit is contained in:
parent
1e9d180bf0
commit
0b336ca8c5
|
@ -3,7 +3,7 @@ use crate::filter_pass::FilterPass;
|
|||
use crate::framebuffer::Framebuffer;
|
||||
use crate::render_target::RenderTarget;
|
||||
use crate::util;
|
||||
use crate::util::{GlImage, RingBuffer, Size, Texture, Viewport};
|
||||
use crate::util::{GlImage, InlineRingBuffer, Size, Texture, Viewport};
|
||||
use gl::types::{GLenum, GLint, GLsizei, GLsizeiptr, GLuint};
|
||||
use librashader::image::Image;
|
||||
use librashader::{FilterMode, ShaderSource};
|
||||
|
@ -373,7 +373,7 @@ impl FilterChain {
|
|||
|
||||
let ubo_ring = if let Some(ubo) = &reflection.ubo {
|
||||
let size = ubo.size;
|
||||
let mut ring: RingBuffer<GLuint, 16> = RingBuffer::new();
|
||||
let mut ring: InlineRingBuffer<GLuint, 16> = InlineRingBuffer::new();
|
||||
unsafe {
|
||||
gl::GenBuffers(16, ring.items_mut().as_mut_ptr());
|
||||
for buffer in ring.items() {
|
||||
|
|
|
@ -13,14 +13,14 @@ use rustc_hash::FxHashMap;
|
|||
use crate::binding::{UniformBinding, UniformLocation, VariableLocation};
|
||||
use crate::filter_chain::FilterCommon;
|
||||
use crate::render_target::RenderTarget;
|
||||
use crate::util::{RingBuffer, Size, Texture, Viewport};
|
||||
use crate::util::{InlineRingBuffer, RingBuffer, Size, Texture, Viewport};
|
||||
|
||||
pub struct FilterPass {
|
||||
pub reflection: ShaderReflection,
|
||||
pub compiled: ShaderCompilerOutput<String, GlslangGlslContext>,
|
||||
pub program: GLuint,
|
||||
pub ubo_location: UniformLocation<GLuint>,
|
||||
pub ubo_ring: Option<RingBuffer<GLuint, 16>>,
|
||||
pub ubo_ring: Option<InlineRingBuffer<GLuint, 16>>,
|
||||
pub uniform_buffer: Box<[u8]>,
|
||||
pub push_buffer: Box<[u8]>,
|
||||
pub variable_bindings: FxHashMap<UniformBinding, (VariableLocation, MemberOffset)>,
|
||||
|
@ -290,7 +290,7 @@ impl FilterPass {
|
|||
MemberOffset::PushConstant(offset) => (&mut self.push_buffer, *offset),
|
||||
};
|
||||
|
||||
FilterPass::build_vec4(location.location(), &mut buffer[offset..][..4], fb_size)
|
||||
FilterPass::build_vec4(location.location(), &mut buffer[offset..][..16], fb_size)
|
||||
}
|
||||
|
||||
// bind FinalViewportSize
|
||||
|
@ -304,7 +304,7 @@ impl FilterPass {
|
|||
};
|
||||
FilterPass::build_vec4(
|
||||
location.location(),
|
||||
&mut buffer[offset..][..4],
|
||||
&mut buffer[offset..][..16],
|
||||
viewport.output.size,
|
||||
)
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ impl FilterPass {
|
|||
};
|
||||
FilterPass::build_vec4(
|
||||
location.location(),
|
||||
&mut buffer[offset..][..4],
|
||||
&mut buffer[offset..][..16],
|
||||
original.image.size,
|
||||
);
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ impl FilterPass {
|
|||
};
|
||||
FilterPass::build_vec4(
|
||||
location.location(),
|
||||
&mut buffer[offset..][..4],
|
||||
&mut buffer[offset..][..16],
|
||||
source.image.size,
|
||||
);
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ impl FilterPass {
|
|||
};
|
||||
FilterPass::build_vec4(
|
||||
location.location(),
|
||||
&mut buffer[offset..][..4],
|
||||
&mut buffer[offset..][..16],
|
||||
output.image.size,
|
||||
);
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ impl FilterPass {
|
|||
};
|
||||
FilterPass::build_vec4(
|
||||
location.location(),
|
||||
&mut buffer[offset..][..4],
|
||||
&mut buffer[offset..][..16],
|
||||
lut.image.size,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ mod tests {
|
|||
#[test]
|
||||
fn triangle() {
|
||||
let (glfw, window, events, shader, vao) = hello_triangle::setup();
|
||||
let mut filter = FilterChain::load("../test/basic.slangp").unwrap();
|
||||
let mut filter = FilterChain::load("../test/slang-shaders/crt/crt-geom.slangp").unwrap();
|
||||
|
||||
// FilterChain::load("../test/slang-shaders/crt/crt-royale.slangp").unwrap();
|
||||
|
||||
|
|
|
@ -43,12 +43,22 @@ pub struct GlImage {
|
|||
pub padded_size: Size,
|
||||
}
|
||||
|
||||
impl<T, const SIZE: usize> RingBuffer<T, SIZE> {
|
||||
pub fn current(&self) -> &T {
|
||||
pub trait RingBuffer<T> {
|
||||
fn current(&self) -> &T;
|
||||
fn current_mut(&mut self) -> &mut T;
|
||||
fn next(&mut self);
|
||||
}
|
||||
|
||||
impl<T, const SIZE: usize> RingBuffer<T> for InlineRingBuffer<T, SIZE> {
|
||||
fn current(&self) -> &T {
|
||||
&self.items[self.index]
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
fn current_mut(&mut self) -> &mut T {
|
||||
&mut self.items[self.index]
|
||||
}
|
||||
|
||||
fn next(&mut self) {
|
||||
self.index += 1;
|
||||
if self.index >= SIZE {
|
||||
self.index = 0
|
||||
|
@ -56,12 +66,12 @@ impl<T, const SIZE: usize> RingBuffer<T, SIZE> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct RingBuffer<T, const SIZE: usize> {
|
||||
pub struct InlineRingBuffer<T, const SIZE: usize> {
|
||||
items: [T; SIZE],
|
||||
index: usize,
|
||||
}
|
||||
|
||||
impl<T, const SIZE: usize> RingBuffer<T, SIZE>
|
||||
impl<T, const SIZE: usize> InlineRingBuffer<T, SIZE>
|
||||
where
|
||||
T: Copy,
|
||||
T: Default,
|
||||
|
@ -82,6 +92,53 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct AllocRingBuffer<T> {
|
||||
items: Box<[T]>,
|
||||
index: usize
|
||||
}
|
||||
|
||||
impl<T> AllocRingBuffer<T>
|
||||
where
|
||||
T: Default,
|
||||
{
|
||||
pub fn new(len: usize) -> Self {
|
||||
let mut items = Vec::new();
|
||||
items.resize_with(len, T::default);
|
||||
|
||||
Self {
|
||||
items: items.into_boxed_slice(),
|
||||
index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn items(&self) -> &[T] {
|
||||
&self.items
|
||||
}
|
||||
|
||||
pub fn items_mut(&mut self) -> &mut [T] {
|
||||
&mut self.items
|
||||
}
|
||||
}
|
||||
|
||||
impl <T> RingBuffer<T> for AllocRingBuffer<T> {
|
||||
fn current(&self) -> &T {
|
||||
&self.items[self.index]
|
||||
}
|
||||
|
||||
fn current_mut(&mut self) -> &mut T {
|
||||
&mut self.items[self.index]
|
||||
}
|
||||
|
||||
fn next(&mut self) {
|
||||
self.index += 1;
|
||||
if self.index >= self.items.len() {
|
||||
self.index = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub unsafe fn gl_compile_shader(stage: GLenum, source: &str) -> GLuint {
|
||||
let shader = gl::CreateShader(stage);
|
||||
gl::ShaderSource(
|
||||
|
|
Loading…
Reference in a new issue