rt: fix TAIT usages

This commit is contained in:
chyyran 2023-07-20 01:10:19 -04:00 committed by Ronny Chan
parent 3735659604
commit 59cc3deb09
4 changed files with 134 additions and 102 deletions

View file

@ -1,7 +1,7 @@
use crate::texture::{D3D11InputView, InputTexture, LutTexture}; use crate::texture::{D3D11InputView, InputTexture, LutTexture};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::{ShaderPreset, TextureConfig}; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::targets::HLSL; use librashader_reflect::back::targets::HLSL;
use librashader_reflect::back::{CompileReflectShader, CompileShader}; use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation; use librashader_reflect::front::GlslangCompilation;
@ -45,9 +45,6 @@ pub struct FilterMutable {
pub(crate) parameters: FxHashMap<String, f32>, pub(crate) parameters: FxHashMap<String, f32>,
} }
type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
/// A Direct3D 11 filter chain. /// A Direct3D 11 filter chain.
pub struct FilterChainD3D11 { pub struct FilterChainD3D11 {
pub(crate) common: FilterCommon, pub(crate) common: FilterCommon,
@ -75,6 +72,24 @@ pub(crate) struct FilterCommon {
pub(crate) draw_quad: DrawQuad, pub(crate) draw_quad: DrawQuad,
} }
type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
fn compile_passes(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
HLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))
}
impl FilterChainD3D11 { impl FilterChainD3D11 {
/// Load the shader preset at the given path into a filter chain. /// Load the shader preset at the given path into a filter chain.
pub unsafe fn load_from_path( pub unsafe fn load_from_path(
@ -121,17 +136,7 @@ impl FilterChainD3D11 {
) -> error::Result<FilterChainD3D11> { ) -> error::Result<FilterChainD3D11> {
let disable_cache = options.map_or(false, |o| o.disable_cache); let disable_cache = options.map_or(false, |o| o.disable_cache);
let (passes, semantics) = if !disable_cache { let (passes, semantics) = compile_passes(preset.shaders, &preset.textures, disable_cache)?;
HLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
preset.shaders,
&preset.textures,
)?
} else {
HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
preset.shaders,
&preset.textures,
)?
};
let samplers = SamplerSet::new(device)?; let samplers = SamplerSet::new(device)?;

View file

@ -15,7 +15,7 @@ use crate::samplers::SamplerSet;
use crate::texture::{D3D12InputImage, D3D12OutputView, InputTexture, OutputDescriptor}; use crate::texture::{D3D12InputImage, D3D12OutputView, InputTexture, OutputDescriptor};
use crate::{error, util}; use crate::{error, util};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::{ShaderPreset, TextureConfig}; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::targets::{DXIL, HLSL}; use librashader_reflect::back::targets::{DXIL, HLSL};
use librashader_reflect::back::{CompileReflectShader, CompileShader}; use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation; use librashader_reflect::front::GlslangCompilation;
@ -54,11 +54,6 @@ use rayon::prelude::*;
const MIPMAP_RESERVED_WORKHEAP_DESCRIPTORS: usize = 4096; const MIPMAP_RESERVED_WORKHEAP_DESCRIPTORS: usize = 4096;
type DxilShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation> + Send>;
type HlslShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
pub struct FilterMutable { pub struct FilterMutable {
pub(crate) passes_enabled: usize, pub(crate) passes_enabled: usize,
pub(crate) parameters: FxHashMap<String, f32>, pub(crate) parameters: FxHashMap<String, f32>,
@ -148,6 +143,41 @@ impl Drop for FrameResiduals {
} }
} }
type DxilShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation> + Send>;
fn compile_passes_dxil(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<DxilShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
DXIL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
DXIL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))
}
type HlslShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
fn compile_passes_hlsl(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<HlslShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
HLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))
}
impl FilterChainD3D12 { impl FilterChainD3D12 {
/// Load the shader preset at the given path into a filter chain. /// Load the shader preset at the given path into a filter chain.
pub unsafe fn load_from_path( pub unsafe fn load_from_path(
@ -219,29 +249,8 @@ impl FilterChainD3D12 {
let shader_copy = preset.shaders.clone(); let shader_copy = preset.shaders.clone();
let disable_cache = options.map_or(false, |o| o.disable_cache); let disable_cache = options.map_or(false, |o| o.disable_cache);
let (passes, semantics) = if !disable_cache { let (passes, semantics) = compile_passes_dxil(preset.shaders, &preset.textures, disable_cache)?;
DXIL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>( let (hlsl_passes, _) = compile_passes_hlsl(shader_copy, &preset.textures, disable_cache)?;
preset.shaders,
&preset.textures,
)?
} else {
DXIL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
preset.shaders,
&preset.textures,
)?
};
let (hlsl_passes, _) = if !disable_cache {
HLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
shader_copy,
&preset.textures,
)?
} else {
HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
shader_copy,
&preset.textures,
)?
};
let samplers = SamplerSet::new(device)?; let samplers = SamplerSet::new(device)?;
let mipmap_gen = D3D12MipmapGen::new(device, false)?; let mipmap_gen = D3D12MipmapGen::new(device, false)?;
@ -368,7 +377,7 @@ impl FilterChainD3D12 {
texture.filter_mode, texture.filter_mode,
texture.wrap_mode, texture.wrap_mode,
texture.mipmap, texture.mipmap,
gc gc,
)?; )?;
luts.insert(index, texture); luts.insert(index, texture);
} }
@ -424,22 +433,32 @@ impl FilterChainD3D12 {
let (sampler_work_heaps, _, sampler_heap_handle) = let (sampler_work_heaps, _, sampler_heap_handle) =
unsafe { sampler_work_heap.suballocate(MAX_BINDINGS_COUNT as usize, 0) }; unsafe { sampler_work_heap.suballocate(MAX_BINDINGS_COUNT as usize, 0) };
let filters: Vec<error::Result<_>> = passes.into_par_iter() let filters: Vec<error::Result<_>> = passes
.into_par_iter()
.zip(hlsl_passes) .zip(hlsl_passes)
.zip(work_heaps) .zip(work_heaps)
.zip(sampler_work_heaps) .zip(sampler_work_heaps)
.enumerate() .enumerate()
.map_init( .map_init(
|| { || {
let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? }; let validator: IDxcValidator =
unsafe { DxcCreateInstance(&CLSID_DxcValidator)? };
let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? }; let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? };
let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? }; let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? };
Ok::<_, FilterChainError>((validator, library, compiler)) Ok::<_, FilterChainError>((validator, library, compiler))
}, },
|dxc, (index, ((((config, source, mut dxil), |dxc,
(_, _, mut hlsl)), mut texture_heap), mut sampler_heap))| { (
index,
(
(((config, source, mut dxil), (_, _, mut hlsl)), mut texture_heap),
mut sampler_heap,
),
)| {
let Ok((validator, library, compiler)) = dxc else { let Ok((validator, library, compiler)) = dxc else {
return Err(FilterChainError::Direct3DOperationError("Could not initialize DXC for thread")); return Err(FilterChainError::Direct3DOperationError(
"Could not initialize DXC for thread",
));
}; };
let dxil_reflection = dxil.reflect(index, semantics)?; let dxil_reflection = dxil.reflect(index, semantics)?;
@ -453,8 +472,8 @@ impl FilterChainD3D12 {
source.format source.format
} else { } else {
ImageFormat::R8G8B8A8Unorm ImageFormat::R8G8B8A8Unorm
}.into(); }
.into();
// incredibly cursed. // incredibly cursed.
let (reflection, graphics_pipeline) = if !force_hlsl && let (reflection, graphics_pipeline) = if !force_hlsl &&
@ -494,11 +513,11 @@ impl FilterChainD3D12 {
let uniform_storage = UniformStorage::new_with_storage( let uniform_storage = UniformStorage::new_with_storage(
RawD3D12Buffer::new(D3D12Buffer::new(device, ubo_size)?)?, RawD3D12Buffer::new(D3D12Buffer::new(device, ubo_size)?)?,
RawD3D12Buffer::new(D3D12Buffer::new(device, push_size)?)? RawD3D12Buffer::new(D3D12Buffer::new(device, push_size)?)?,
); );
let uniform_bindings =
let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset()); reflection.meta.create_binding_map(|param| param.offset());
let texture_heap = texture_heap.alloc_range()?; let texture_heap = texture_heap.alloc_range()?;
let sampler_heap = sampler_heap.alloc_range()?; let sampler_heap = sampler_heap.alloc_range()?;
@ -513,8 +532,9 @@ impl FilterChainD3D12 {
sampler_heap, sampler_heap,
source, source,
}) })
},
}).collect(); )
.collect();
let filters: error::Result<Vec<_>> = filters.into_iter().collect(); let filters: error::Result<Vec<_>> = filters.into_iter().collect();
let filters = filters?; let filters = filters?;

View file

@ -12,7 +12,7 @@ use crate::{error, GLImage};
use gl::types::GLuint; use gl::types::GLuint;
use librashader_common::Viewport; use librashader_common::Viewport;
use librashader_presets::ShaderPreset; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::cross::GlslVersion; use librashader_reflect::back::cross::GlslVersion;
use librashader_reflect::back::targets::GLSL; use librashader_reflect::back::targets::GLSL;
use librashader_reflect::back::{CompileReflectShader, CompileShader}; use librashader_reflect::back::{CompileReflectShader, CompileShader};
@ -98,6 +98,21 @@ impl<T: GLInterface> FilterChainImpl<T> {
} }
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<GLSL, GlslangCompilation>>; type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<GLSL, GlslangCompilation>>;
fn compile_passes(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
GLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
GLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))
}
impl<T: GLInterface> FilterChainImpl<T> { impl<T: GLInterface> FilterChainImpl<T> {
/// Load a filter chain from a pre-parsed `ShaderPreset`. /// Load a filter chain from a pre-parsed `ShaderPreset`.
@ -106,19 +121,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
options: Option<&FilterChainOptionsGL>, options: Option<&FilterChainOptionsGL>,
) -> error::Result<Self> { ) -> error::Result<Self> {
let disable_cache = options.map_or(false, |o| o.disable_cache); let disable_cache = options.map_or(false, |o| o.disable_cache);
let (passes, semantics) = compile_passes(preset.shaders, &preset.textures, disable_cache)?;
let (passes, semantics) = if !disable_cache {
GLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
preset.shaders,
&preset.textures,
)?
} else {
GLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
preset.shaders,
&preset.textures,
)?
};
let version = options.map_or_else(gl_get_version, |o| gl_u16_to_version(o.glsl_version)); let version = options.map_or_else(gl_get_version, |o| gl_u16_to_version(o.glsl_version));
// initialize passes // initialize passes

View file

@ -14,7 +14,7 @@ use ash::vk;
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use gpu_allocator::vulkan::Allocator; use gpu_allocator::vulkan::Allocator;
use librashader_presets::{ShaderPreset, TextureConfig}; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::targets::SPIRV; use librashader_reflect::back::targets::SPIRV;
use librashader_reflect::back::{CompileReflectShader, CompileShader}; use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation; use librashader_reflect::front::GlslangCompilation;
@ -46,9 +46,6 @@ pub struct VulkanObjects {
// pub(crate) memory_properties: vk::PhysicalDeviceMemoryProperties, // pub(crate) memory_properties: vk::PhysicalDeviceMemoryProperties,
} }
type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<SPIRV, GlslangCompilation> + Send>;
/// A collection of handles needed to access the Vulkan instance. /// A collection of handles needed to access the Vulkan instance.
#[derive(Clone)] #[derive(Clone)]
pub struct VulkanInstance { pub struct VulkanInstance {
@ -208,6 +205,24 @@ impl Drop for FrameResiduals {
} }
} }
type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<SPIRV, GlslangCompilation> + Send>;
fn compile_passes(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
SPIRV::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
SPIRV::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))
}
impl FilterChainVulkan { impl FilterChainVulkan {
/// Load the shader preset at the given path into a filter chain. /// Load the shader preset at the given path into a filter chain.
pub unsafe fn load_from_path<V, E>( pub unsafe fn load_from_path<V, E>(
@ -307,18 +322,7 @@ impl FilterChainVulkan {
FilterChainError: From<E>, FilterChainError: From<E>,
{ {
let disable_cache = options.map_or(false, |o| o.disable_cache); let disable_cache = options.map_or(false, |o| o.disable_cache);
let (passes, semantics) = compile_passes(preset.shaders, &preset.textures, disable_cache)?;
let (passes, semantics) = if !disable_cache {
SPIRV::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
preset.shaders,
&preset.textures,
)?
} else {
SPIRV::compile_preset_passes::<GlslangCompilation, FilterChainError>(
preset.shaders,
&preset.textures,
)?
};
let device = vulkan.try_into().map_err(From::from)?; let device = vulkan.try_into().map_err(From::from)?;