feat: cubic filtering

This commit is contained in:
galister
2024-07-11 16:23:04 +09:00
parent 80bd65235d
commit bdc500973c
6 changed files with 214 additions and 221 deletions

383
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@ use openxr as xr;
use smallvec::SmallVec; use smallvec::SmallVec;
use vulkano::{ use vulkano::{
image::{sampler::Filter, sys::RawImage, view::ImageView, ImageCreateInfo, ImageUsage}, image::{sys::RawImage, view::ImageView, ImageCreateInfo, ImageUsage},
pipeline::graphics::color_blend::AttachmentBlend, pipeline::graphics::color_blend::AttachmentBlend,
Handle, Handle,
}; };
@@ -96,9 +96,11 @@ impl SwapchainRenderData {
let target_extent = render_target.image().extent(); let target_extent = render_target.image().extent();
let set0 = self let set0 = self.pipeline.uniform_sampler(
.pipeline 0,
.uniform_sampler(0, view.clone(), Filter::Linear)?; view.clone(),
command_buffer.graphics.texture_filtering,
)?;
let set1 = self.pipeline.uniform_buffer(1, vec![alpha])?; let set1 = self.pipeline.uniform_buffer(1, vec![alpha])?;

View File

@@ -87,7 +87,7 @@ impl PreviewState {
) )
}?; }?;
let set0 = pipeline let set0 = pipeline
.uniform_sampler(0, view.clone(), Filter::Linear) .uniform_sampler(0, view.clone(), pipeline.graphics.texture_filtering)
.unwrap(); .unwrap();
let pass = pipeline let pass = pipeline

View File

@@ -124,6 +124,7 @@ pub struct WlxGraphics {
pub queue: Arc<Queue>, pub queue: Arc<Queue>,
pub native_format: Format, pub native_format: Format,
pub texture_filtering: Filter,
pub memory_allocator: Arc<StandardMemoryAllocator>, pub memory_allocator: Arc<StandardMemoryAllocator>,
pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>, pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
@@ -267,6 +268,10 @@ impl WlxGraphics {
.ext_image_drm_format_modifier; .ext_image_drm_format_modifier;
} }
if physical_device.supported_extensions().ext_filter_cubic {
device_extensions.ext_filter_cubic = true;
}
let device_extensions_raw = device_extensions let device_extensions_raw = device_extensions
.into_iter() .into_iter()
.filter_map(|(name, enabled)| { .filter_map(|(name, enabled)| {
@@ -300,6 +305,12 @@ impl WlxGraphics {
dynamic_rendering.p_next = device_create_info.p_next as _; dynamic_rendering.p_next = device_create_info.p_next as _;
device_create_info.p_next = (&mut dynamic_rendering) as *const _ as *const c_void; device_create_info.p_next = (&mut dynamic_rendering) as *const _ as *const c_void;
let texture_filtering = if physical_device.supported_extensions().ext_filter_cubic {
Filter::Cubic
} else {
Filter::Linear
};
let (device, mut queues) = unsafe { let (device, mut queues) = unsafe {
let vk_device = xr_instance let vk_device = xr_instance
.create_vulkan_device( .create_vulkan_device(
@@ -368,6 +379,7 @@ impl WlxGraphics {
device, device,
queue, queue,
native_format: Format::R8G8B8A8_UNORM, native_format: Format::R8G8B8A8_UNORM,
texture_filtering,
memory_allocator, memory_allocator,
command_buffer_allocator, command_buffer_allocator,
descriptor_set_allocator, descriptor_set_allocator,
@@ -430,6 +442,10 @@ impl WlxGraphics {
p.supported_extensions().ext_image_drm_format_modifier; p.supported_extensions().ext_image_drm_format_modifier;
} }
if p.supported_extensions().ext_filter_cubic {
my_extensions.ext_filter_cubic = true;
}
log::debug!( log::debug!(
"Device exts for {}: {:?}", "Device exts for {}: {:?}",
p.properties().device_name, p.properties().device_name,
@@ -459,6 +475,12 @@ impl WlxGraphics {
physical_device.properties().device_name, physical_device.properties().device_name,
); );
let texture_filtering = if physical_device.supported_extensions().ext_filter_cubic {
Filter::Cubic
} else {
Filter::Linear
};
let (device, mut queues) = Device::new( let (device, mut queues) = Device::new(
physical_device, physical_device,
DeviceCreateInfo { DeviceCreateInfo {
@@ -509,6 +531,7 @@ impl WlxGraphics {
queue, queue,
memory_allocator, memory_allocator,
native_format: Format::R8G8B8A8_UNORM, native_format: Format::R8G8B8A8_UNORM,
texture_filtering,
command_buffer_allocator, command_buffer_allocator,
descriptor_set_allocator, descriptor_set_allocator,
quad_indices, quad_indices,
@@ -644,6 +667,7 @@ impl WlxGraphics {
queue, queue,
memory_allocator, memory_allocator,
native_format, native_format,
texture_filtering: Filter::Linear,
command_buffer_allocator, command_buffer_allocator,
descriptor_set_allocator, descriptor_set_allocator,
quad_indices, quad_indices,

View File

@@ -5,7 +5,7 @@ use glam::{Vec2, Vec4};
use vulkano::{ use vulkano::{
command_buffer::CommandBufferUsage, command_buffer::CommandBufferUsage,
format::Format, format::Format,
image::{sampler::Filter, view::ImageView, ImageLayout}, image::{view::ImageView, ImageLayout},
}; };
use crate::{ use crate::{
@@ -353,8 +353,10 @@ impl<D, S> Canvas<D, S> {
ImageLayout::TransferSrcOptimal, ImageLayout::TransferSrcOptimal,
)?; )?;
let set_fg = pipeline_final.uniform_sampler(0, view_fg.clone(), Filter::Linear)?; let set_fg =
let set_bg = pipeline_final.uniform_sampler(0, view_bg.clone(), Filter::Linear)?; pipeline_final.uniform_sampler(0, view_fg.clone(), graphics.texture_filtering)?;
let set_bg =
pipeline_final.uniform_sampler(0, view_bg.clone(), graphics.texture_filtering)?;
let pass_fg = pipeline_final.create_pass( let pass_fg = pipeline_final.create_pass(
[width as _, height as _], [width as _, height as _],
vertex_buffer.clone(), vertex_buffer.clone(),
@@ -761,7 +763,7 @@ impl<D, S> Control<D, S> {
let set0 = canvas.pipeline_fg_glyph.uniform_sampler( let set0 = canvas.pipeline_fg_glyph.uniform_sampler(
0, 0,
ImageView::new_default(tex)?, ImageView::new_default(tex)?,
Filter::Linear, app.graphics.texture_filtering,
)?; )?;
let set1 = canvas let set1 = canvas
.pipeline_fg_glyph .pipeline_fg_glyph
@@ -809,7 +811,7 @@ impl<D, S> Control<D, S> {
let set0 = canvas.pipeline_fg_glyph.uniform_sampler( let set0 = canvas.pipeline_fg_glyph.uniform_sampler(
0, 0,
ImageView::new_default(tex)?, ImageView::new_default(tex)?,
Filter::Linear, app.graphics.texture_filtering,
)?; )?;
let set1 = canvas let set1 = canvas
.pipeline_fg_glyph .pipeline_fg_glyph

View File

@@ -229,7 +229,9 @@ impl ScreenPipeline {
.graphics .graphics
.create_command_buffer(CommandBufferUsage::OneTimeSubmit)?; .create_command_buffer(CommandBufferUsage::OneTimeSubmit)?;
let view = ImageView::new_default(image)?; let view = ImageView::new_default(image)?;
let set0 = self.pipeline.uniform_sampler(0, view, Filter::Linear)?; let set0 = self
.pipeline
.uniform_sampler(0, view, app.graphics.texture_filtering)?;
let pass = self.pipeline.create_pass( let pass = self.pipeline.create_pass(
self.extentf, self.extentf,