rt(mtl): reenable mipmaps

This commit is contained in:
chyyran 2024-02-13 02:34:26 -05:00 committed by Ronny Chan
parent bceb0623a3
commit 004b073b1a
3 changed files with 24 additions and 28 deletions

View file

@ -134,7 +134,7 @@ impl FilterChainMetal {
.map(|texture| Image::<BGRA8>::load(&texture.path, UVDirection::TopLeft)) .map(|texture| Image::<BGRA8>::load(&texture.path, UVDirection::TopLeft))
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?; .collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() { for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let texture = LutTexture::new(device, image, texture)?; let texture = LutTexture::new(device, image, texture, &mipmapper)?;
luts.insert(index, texture); luts.insert(index, texture);
} }
@ -397,7 +397,8 @@ impl FilterChainMetal {
source source
.texture .texture
.setLabel(Some(&*NSString::from_str("sourcetex"))); .setLabel(Some(&*NSString::from_str("librashader_sourcetex")));
// swap output and feedback **before** recording command buffers // swap output and feedback **before** recording command buffers
std::mem::swap( std::mem::swap(
&mut self.output_framebuffers, &mut self.output_framebuffers,

View file

@ -1,11 +1,13 @@
use crate::error::{FilterChainError, Result}; use crate::error::{FilterChainError, Result};
use crate::texture::InputTexture; use crate::texture::InputTexture;
use icrate::Metal::{ use icrate::Metal::{
MTLDevice, MTLOrigin, MTLPixelFormatBGRA8Unorm, MTLRegion, MTLSize, MTLTexture, MTLBlitCommandEncoder, MTLDevice, MTLOrigin, MTLPixelFormatBGRA8Unorm, MTLRegion, MTLSize,
MTLTextureDescriptor, MTLTextureUsageShaderRead, MTLTexture, MTLTextureDescriptor, MTLTextureUsageShaderRead,
}; };
use librashader_presets::TextureConfig; use librashader_presets::TextureConfig;
use librashader_runtime::image::{Image, BGRA8}; use librashader_runtime::image::{Image, BGRA8};
use librashader_runtime::scaling::MipmapSize;
use objc2::rc::Id;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use std::ffi::c_void; use std::ffi::c_void;
use std::ptr::NonNull; use std::ptr::NonNull;
@ -23,6 +25,7 @@ impl LutTexture {
device: &ProtocolObject<dyn MTLDevice>, device: &ProtocolObject<dyn MTLDevice>,
image: Image<BGRA8>, image: Image<BGRA8>,
config: &TextureConfig, config: &TextureConfig,
mipmapper: &ProtocolObject<dyn MTLBlitCommandEncoder>,
) -> Result<Self> { ) -> Result<Self> {
let descriptor = unsafe { let descriptor = unsafe {
let descriptor = let descriptor =
@ -34,13 +37,11 @@ impl LutTexture {
); );
descriptor.setSampleCount(1); descriptor.setSampleCount(1);
// descriptor.setMipmapLevelCount(if config.mipmap { descriptor.setMipmapLevelCount(if config.mipmap {
// image.size.calculate_miplevels() as usize image.size.calculate_miplevels() as usize
// } else { } else {
// 1 1
// }); });
descriptor.setMipmapLevelCount(1);
descriptor.setUsage(MTLTextureUsageShaderRead); descriptor.setUsage(MTLTextureUsageShaderRead);
@ -71,7 +72,7 @@ impl LutTexture {
} }
if config.mipmap { if config.mipmap {
// mipmapper.generateMipmapsForTexture(&texture); mipmapper.generateMipmapsForTexture(&texture);
} }
Ok(LutTexture(InputTexture { Ok(LutTexture(InputTexture {

View file

@ -1,14 +1,9 @@
use crate::error::{FilterChainError, Result}; use crate::error::{FilterChainError, Result};
use crate::select_optimal_pixel_format; use crate::select_optimal_pixel_format;
use icrate::Metal::{ use icrate::Metal::{MTLBlitCommandEncoder, MTLCommandBuffer, MTLCommandEncoder, MTLDevice, MTLPixelFormat, MTLStorageModePrivate, MTLTexture, MTLTextureDescriptor, MTLTextureUsageRenderTarget, MTLTextureUsageShaderRead, MTLTextureUsageShaderWrite};
MTLBlitCommandEncoder, MTLCommandBuffer, MTLCommandEncoder, MTLDevice,
MTLParallelRenderCommandEncoder, MTLPixelFormat, MTLRenderCommandEncoder, MTLTexture,
MTLTextureDescriptor, MTLTextureUsageRenderTarget, MTLTextureUsageShaderRead,
MTLTextureUsageShaderWrite,
};
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode}; use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use librashader_runtime::scaling::{ScaleFramebuffer, ViewportSize}; use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize};
use objc2::rc::Id; use objc2::rc::Id;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
@ -60,18 +55,17 @@ impl OwnedTexture {
select_optimal_pixel_format(format), select_optimal_pixel_format(format),
size.width as usize, size.width as usize,
size.height as usize, size.height as usize,
max_miplevels <= 1, max_miplevels > 1,
); );
descriptor.setSampleCount(1); descriptor.setSampleCount(1);
// descriptor.setMipmapLevelCount(if max_miplevels <= 1 { descriptor.setMipmapLevelCount(if max_miplevels > 1 {
// size.calculate_miplevels() as usize size.calculate_miplevels() as usize
// } else { } else {
// 1 1
// }); });
descriptor.setMipmapLevelCount(1);
descriptor.setStorageMode(MTLStorageModePrivate);
descriptor.setUsage( descriptor.setUsage(
MTLTextureUsageShaderRead MTLTextureUsageShaderRead
| MTLTextureUsageShaderWrite | MTLTextureUsageShaderWrite
@ -142,7 +136,7 @@ impl OwnedTexture {
let mipmapper = cmd let mipmapper = cmd
.blitCommandEncoder() .blitCommandEncoder()
.ok_or(FilterChainError::FailedToCreateCommandBuffer)?; .ok_or(FilterChainError::FailedToCreateCommandBuffer)?;
// mipmapper.generateMipmapsForTexture(&self.texture); mipmapper.generateMipmapsForTexture(&self.texture);
mipmapper.endEncoding(); mipmapper.endEncoding();
Ok(()) Ok(())
} }