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))
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
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);
}
@ -397,7 +397,8 @@ impl FilterChainMetal {
source
.texture
.setLabel(Some(&*NSString::from_str("sourcetex")));
.setLabel(Some(&*NSString::from_str("librashader_sourcetex")));
// swap output and feedback **before** recording command buffers
std::mem::swap(
&mut self.output_framebuffers,

View file

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

View file

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