Merge branch 'SnowflakePowered:master' into master
This commit is contained in:
commit
9f6e5aaac2
24 changed files with 719 additions and 584 deletions
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
|
@ -38,6 +38,9 @@ jobs:
|
|||
python-version: '3.x'
|
||||
- run: pip install meson ninja mako
|
||||
name: Install Meson for spirv-to-dxil-sys
|
||||
- if: runner.os == 'Windows'
|
||||
name: Install winflexbison
|
||||
run: choco install winflexbison3
|
||||
- name: Build dynamic library
|
||||
run: cargo run -p librashader-build-script -- --profile ${{ matrix.profile }}
|
||||
- name: Upload build artifacts
|
||||
|
|
913
Cargo.lock
generated
913
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,7 @@ members = [
|
|||
"librashader-capi",
|
||||
"librashader-build-script"
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.metadata.release]
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize
|
|||
|
||||
let Ok(cache) = cache else {
|
||||
return Ok(CachedCompilation {
|
||||
compilation: T::compile(source)?
|
||||
})
|
||||
compilation: T::compile(source)?,
|
||||
});
|
||||
};
|
||||
|
||||
let key = {
|
||||
|
|
|
@ -18,7 +18,9 @@ impl CacheKey for windows::Win32::Graphics::Direct3D::Dxc::IDxcBlob {
|
|||
|
||||
impl Cacheable for windows::Win32::Graphics::Direct3D::ID3DBlob {
|
||||
fn from_bytes(bytes: &[u8]) -> Option<Self> {
|
||||
let Some(blob) = (unsafe { windows::Win32::Graphics::Direct3D::Fxc::D3DCreateBlob(bytes.len()).ok() }) else {
|
||||
let Some(blob) =
|
||||
(unsafe { windows::Win32::Graphics::Direct3D::Fxc::D3DCreateBlob(bytes.len()).ok() })
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
||||
|
@ -44,11 +46,18 @@ impl Cacheable for windows::Win32::Graphics::Direct3D::Dxc::IDxcBlob {
|
|||
fn from_bytes(bytes: &[u8]) -> Option<Self> {
|
||||
let Some(blob) = (unsafe {
|
||||
windows::Win32::Graphics::Direct3D::Dxc::DxcCreateInstance(
|
||||
&windows::Win32::Graphics::Direct3D::Dxc::CLSID_DxcLibrary)
|
||||
.and_then(|library: windows::Win32::Graphics::Direct3D::Dxc::IDxcUtils| {
|
||||
library.CreateBlob(bytes.as_ptr().cast(), bytes.len() as u32,
|
||||
windows::Win32::Graphics::Direct3D::Dxc::DXC_CP(0))
|
||||
}).ok()
|
||||
&windows::Win32::Graphics::Direct3D::Dxc::CLSID_DxcLibrary,
|
||||
)
|
||||
.and_then(
|
||||
|library: windows::Win32::Graphics::Direct3D::Dxc::IDxcUtils| {
|
||||
library.CreateBlob(
|
||||
bytes.as_ptr().cast(),
|
||||
bytes.len() as u32,
|
||||
windows::Win32::Graphics::Direct3D::Dxc::DXC_CP(0),
|
||||
)
|
||||
},
|
||||
)
|
||||
.ok()
|
||||
}) else {
|
||||
return None;
|
||||
};
|
||||
|
|
|
@ -67,7 +67,7 @@ pub type PFN_libra_error_errno = extern "C" fn(error: libra_error_t) -> LIBRA_ER
|
|||
/// - `error` must be valid and initialized.
|
||||
pub unsafe extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO {
|
||||
let Some(error) = error else {
|
||||
return LIBRA_ERRNO::UNKNOWN_ERROR
|
||||
return LIBRA_ERRNO::UNKNOWN_ERROR;
|
||||
};
|
||||
|
||||
unsafe { error.as_ref().get_code() }
|
||||
|
@ -82,9 +82,7 @@ pub type PFN_libra_error_print = extern "C" fn(error: libra_error_t) -> i32;
|
|||
/// ## Safety
|
||||
/// - `error` must be a valid and initialized instance of `libra_error_t`.
|
||||
pub unsafe extern "C" fn libra_error_print(error: libra_error_t) -> i32 {
|
||||
let Some(error) = error else {
|
||||
return 1
|
||||
};
|
||||
let Some(error) = error else { return 1 };
|
||||
unsafe {
|
||||
let error = error.as_ref();
|
||||
println!("{error:?}: {error}");
|
||||
|
@ -130,9 +128,7 @@ pub unsafe extern "C" fn libra_error_write(
|
|||
error: libra_error_t,
|
||||
out: *mut MaybeUninit<*mut c_char>,
|
||||
) -> i32 {
|
||||
let Some(error) = error else {
|
||||
return 1
|
||||
};
|
||||
let Some(error) = error else { return 1 };
|
||||
if out.is_null() {
|
||||
return 1;
|
||||
}
|
||||
|
@ -140,7 +136,7 @@ pub unsafe extern "C" fn libra_error_write(
|
|||
unsafe {
|
||||
let error = error.as_ref();
|
||||
let Ok(cstring) = CString::new(format!("{error:?}: {error}")) else {
|
||||
return 1
|
||||
return 1;
|
||||
};
|
||||
|
||||
out.write(MaybeUninit::new(cstring.into_raw()))
|
||||
|
|
|
@ -25,7 +25,7 @@ fn read_file(path: impl AsRef<Path>) -> Result<String, PreprocessError> {
|
|||
let buf = e.into_bytes();
|
||||
let decoder = WINDOWS_1252.new_decoder();
|
||||
let Some(len) = decoder.max_utf8_buffer_length_without_replacement(buf.len()) else {
|
||||
return Err(PreprocessError::EncodingError(path.to_path_buf()))
|
||||
return Err(PreprocessError::EncodingError(path.to_path_buf()));
|
||||
};
|
||||
|
||||
let mut latin1_string = String::with_capacity(len);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
//! as input to create a filter chain.
|
||||
//!
|
||||
//! Re-exported as [`librashader::presets`](https://docs.rs/librashader/latest/librashader/presets/index.html).
|
||||
#![feature(drain_filter)]
|
||||
#![feature(extract_if)]
|
||||
|
||||
mod error;
|
||||
mod parse;
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{ParameterConfig, Scale2D, Scaling, ShaderPassConfig, ShaderPreset, T
|
|||
|
||||
pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
||||
let textures: Vec<TextureConfig> = values
|
||||
.drain_filter(|f| matches!(*f, Value::Texture { .. }))
|
||||
.extract_if(|f| matches!(*f, Value::Texture { .. }))
|
||||
.map(|value| {
|
||||
if let Value::Texture {
|
||||
name,
|
||||
|
@ -27,7 +27,7 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
|||
})
|
||||
.collect();
|
||||
let parameters: Vec<ParameterConfig> = values
|
||||
.drain_filter(|f| matches!(*f, Value::Parameter { .. }))
|
||||
.extract_if(|f| matches!(*f, Value::Parameter { .. }))
|
||||
.map(|value| {
|
||||
if let Value::Parameter(name, value) = value {
|
||||
ParameterConfig { name, value }
|
||||
|
@ -64,7 +64,7 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
|||
|v| matches!(*v, Value::Shader(shader_index, _) if shader_index == shader),
|
||||
) {
|
||||
let shader_values: Vec<Value> = values
|
||||
.drain_filter(|v| v.shader_index() == Some(shader))
|
||||
.extract_if(|v| v.shader_index() == Some(shader))
|
||||
.collect();
|
||||
let scale_type = shader_values.iter().find_map(|f| match f {
|
||||
Value::ScaleType(_, value) => Some(*value),
|
||||
|
|
|
@ -187,7 +187,7 @@ fn load_child_reference_strings(
|
|||
|
||||
let mut new_tokens = do_lex(&reference_contents)?;
|
||||
let new_references: Vec<PathBuf> = new_tokens
|
||||
.drain_filter(|token| *token.key.fragment() == "#reference")
|
||||
.extract_if(|token| *token.key.fragment() == "#reference")
|
||||
.map(|value| PathBuf::from(*value.value.fragment()))
|
||||
.collect();
|
||||
|
||||
|
@ -232,7 +232,7 @@ pub fn parse_values(
|
|||
}
|
||||
|
||||
let references: Vec<PathBuf> = tokens
|
||||
.drain_filter(|token| *token.key.fragment() == "#reference")
|
||||
.extract_if(|token| *token.key.fragment() == "#reference")
|
||||
.map(|value| PathBuf::from(*value.value.fragment()))
|
||||
.collect();
|
||||
|
||||
|
@ -254,7 +254,7 @@ pub fn parse_values(
|
|||
// collect all possible parameter names.
|
||||
let mut parameter_names: Vec<&str> = Vec::new();
|
||||
for (_, tokens) in all_tokens.iter_mut() {
|
||||
for token in tokens.drain_filter(|token| *token.key.fragment() == "parameters") {
|
||||
for token in tokens.extract_if(|token| *token.key.fragment() == "parameters") {
|
||||
let parameter_name_string: &str = token.value.fragment();
|
||||
for parameter_name in parameter_name_string.split(';') {
|
||||
parameter_names.push(parameter_name);
|
||||
|
@ -265,7 +265,7 @@ pub fn parse_values(
|
|||
// collect all possible texture names.
|
||||
let mut texture_names: Vec<&str> = Vec::new();
|
||||
for (_, tokens) in all_tokens.iter_mut() {
|
||||
for token in tokens.drain_filter(|token| *token.key.fragment() == "textures") {
|
||||
for token in tokens.extract_if(|token| *token.key.fragment() == "textures") {
|
||||
let texture_name_string: &str = token.value.fragment();
|
||||
for texture_name in texture_name_string.split(';') {
|
||||
texture_names.push(texture_name);
|
||||
|
@ -276,7 +276,7 @@ pub fn parse_values(
|
|||
let mut values = Vec::new();
|
||||
// resolve shader paths.
|
||||
for (path, tokens) in all_tokens.iter_mut() {
|
||||
for token in tokens.drain_filter(|token| parse_indexed_key("shader", token.key).is_ok()) {
|
||||
for token in tokens.extract_if(|token| parse_indexed_key("shader", token.key).is_ok()) {
|
||||
let (_, index) = parse_indexed_key("shader", token.key).map_err(|e| match e {
|
||||
nom::Err::Error(e) | nom::Err::Failure(e) => {
|
||||
let input: Span = e.input;
|
||||
|
@ -307,7 +307,7 @@ pub fn parse_values(
|
|||
// resolve texture paths
|
||||
let mut textures = Vec::new();
|
||||
for (path, tokens) in all_tokens.iter_mut() {
|
||||
for token in tokens.drain_filter(|token| texture_names.contains(token.key.fragment())) {
|
||||
for token in tokens.extract_if(|token| texture_names.contains(token.key.fragment())) {
|
||||
let mut relative_path = path.to_path_buf();
|
||||
relative_path.push(*token.value.fragment());
|
||||
relative_path
|
||||
|
|
|
@ -24,7 +24,7 @@ librashader-preprocess = { path = "../librashader-preprocess", version = "0.1.4"
|
|||
librashader-presets = { path = "../librashader-presets", version = "0.1.4" }
|
||||
|
||||
spirv_cross = { package = "librashader-spirv-cross", version = "0.23", optional = true }
|
||||
spirv-to-dxil = { version = "0.3", optional = true }
|
||||
spirv-to-dxil = { version = "0.4", optional = true }
|
||||
naga = { version = "0.11.0", features = ["glsl-in", "spv-in", "spv-out", "glsl-out", "wgsl-out"], optional = true }
|
||||
|
||||
rspirv = { version = "0.11.0+1.5.4", optional = true }
|
||||
|
|
|
@ -59,6 +59,7 @@ impl CompileShader<DXIL> for WriteSpirV {
|
|||
register_space: 0,
|
||||
base_shader_register: 1,
|
||||
},
|
||||
shader_model_max: sm,
|
||||
..RuntimeConfig::default()
|
||||
};
|
||||
|
||||
|
@ -68,7 +69,6 @@ impl CompileShader<DXIL> for WriteSpirV {
|
|||
None,
|
||||
"main",
|
||||
ShaderStage::Vertex,
|
||||
sm,
|
||||
ValidatorVersion::None,
|
||||
&config,
|
||||
)
|
||||
|
@ -79,7 +79,6 @@ impl CompileShader<DXIL> for WriteSpirV {
|
|||
None,
|
||||
"main",
|
||||
ShaderStage::Fragment,
|
||||
sm,
|
||||
ValidatorVersion::None,
|
||||
&config,
|
||||
)
|
||||
|
|
|
@ -54,10 +54,26 @@ pub(crate) type GlslReflect = CrossReflect<glsl::Target>;
|
|||
|
||||
impl ValidateTypeSemantics<Type> for UniqueSemantics {
|
||||
fn validate_type(&self, ty: &Type) -> Option<TypeInfo> {
|
||||
let (Type::Float { ref array, vecsize, columns, .. }
|
||||
| Type::Int { ref array, vecsize, columns, .. }
|
||||
| Type::UInt { ref array, vecsize, columns, .. }) = *ty else {
|
||||
return None
|
||||
let (Type::Float {
|
||||
ref array,
|
||||
vecsize,
|
||||
columns,
|
||||
..
|
||||
}
|
||||
| Type::Int {
|
||||
ref array,
|
||||
vecsize,
|
||||
columns,
|
||||
..
|
||||
}
|
||||
| Type::UInt {
|
||||
ref array,
|
||||
vecsize,
|
||||
columns,
|
||||
..
|
||||
}) = *ty
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
||||
if !array.is_empty() {
|
||||
|
@ -93,8 +109,14 @@ impl ValidateTypeSemantics<Type> for UniqueSemantics {
|
|||
|
||||
impl ValidateTypeSemantics<Type> for TextureSemantics {
|
||||
fn validate_type(&self, ty: &Type) -> Option<TypeInfo> {
|
||||
let Type::Float { ref array, vecsize, columns, .. } = *ty else {
|
||||
return None
|
||||
let Type::Float {
|
||||
ref array,
|
||||
vecsize,
|
||||
columns,
|
||||
..
|
||||
} = *ty
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
||||
if !array.is_empty() {
|
||||
|
@ -295,7 +317,7 @@ where
|
|||
|
||||
if let Some(parameter) = semantics.uniform_semantics.get_unique_semantic(&name) {
|
||||
let Some(typeinfo) = parameter.semantics.validate_type(&range_type) else {
|
||||
return Err(blame.error(SemanticsErrorKind::InvalidTypeForSemantic(name)))
|
||||
return Err(blame.error(SemanticsErrorKind::InvalidTypeForSemantic(name)));
|
||||
};
|
||||
|
||||
match ¶meter.semantics {
|
||||
|
@ -372,7 +394,7 @@ where
|
|||
}
|
||||
} else if let Some(texture) = semantics.uniform_semantics.get_texture_semantic(&name) {
|
||||
let Some(_typeinfo) = texture.semantics.validate_type(&range_type) else {
|
||||
return Err(blame.error(SemanticsErrorKind::InvalidTypeForSemantic(name)))
|
||||
return Err(blame.error(SemanticsErrorKind::InvalidTypeForSemantic(name)));
|
||||
};
|
||||
|
||||
if let TextureSemantics::PassOutput = texture.semantics {
|
||||
|
@ -488,8 +510,15 @@ where
|
|||
semantics: &ShaderSemantics,
|
||||
meta: &mut BindingMeta,
|
||||
) -> Result<(), ShaderReflectError> {
|
||||
let Some(semantic) = semantics.texture_semantics.get_texture_semantic(texture.name) else {
|
||||
return Err(SemanticErrorBlame::Fragment.error(SemanticsErrorKind::UnknownSemantics(texture.name.to_string())))
|
||||
let Some(semantic) = semantics
|
||||
.texture_semantics
|
||||
.get_texture_semantic(texture.name)
|
||||
else {
|
||||
return Err(
|
||||
SemanticErrorBlame::Fragment.error(SemanticsErrorKind::UnknownSemantics(
|
||||
texture.name.to_string(),
|
||||
)),
|
||||
);
|
||||
};
|
||||
|
||||
if semantic.semantics == TextureSemantics::PassOutput && semantic.index >= pass_number {
|
||||
|
|
|
@ -361,7 +361,9 @@ impl TextureSemanticMap for FxHashMap<String, Semantic<TextureSemantics>> {
|
|||
{
|
||||
if semantics.is_indexed() {
|
||||
let index = &name[semantics.texture_name().len()..];
|
||||
let Ok(index) = usize::from_str(index) else {return None};
|
||||
let Ok(index) = usize::from_str(index) else {
|
||||
return None;
|
||||
};
|
||||
return Some(Semantic {
|
||||
semantics: *semantics,
|
||||
index,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::texture::{D3D11InputView, InputTexture, LutTexture};
|
||||
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::{CompileReflectShader, CompileShader};
|
||||
use librashader_reflect::front::GlslangCompilation;
|
||||
|
@ -45,9 +45,6 @@ pub struct FilterMutable {
|
|||
pub(crate) parameters: FxHashMap<String, f32>,
|
||||
}
|
||||
|
||||
type ShaderPassMeta =
|
||||
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
|
||||
|
||||
/// A Direct3D 11 filter chain.
|
||||
pub struct FilterChainD3D11 {
|
||||
pub(crate) common: FilterCommon,
|
||||
|
@ -75,6 +72,24 @@ pub(crate) struct FilterCommon {
|
|||
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 {
|
||||
/// Load the shader preset at the given path into a filter chain.
|
||||
pub unsafe fn load_from_path(
|
||||
|
@ -121,17 +136,7 @@ impl FilterChainD3D11 {
|
|||
) -> error::Result<FilterChainD3D11> {
|
||||
let disable_cache = options.map_or(false, |o| o.disable_cache);
|
||||
|
||||
let (passes, semantics) = if !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 (passes, semantics) = compile_passes(preset.shaders, &preset.textures, disable_cache)?;
|
||||
|
||||
let samplers = SamplerSet::new(device)?;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::samplers::SamplerSet;
|
|||
use crate::texture::{D3D12InputImage, D3D12OutputView, InputTexture, OutputDescriptor};
|
||||
use crate::{error, util};
|
||||
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::{CompileReflectShader, CompileShader};
|
||||
use librashader_reflect::front::GlslangCompilation;
|
||||
|
@ -54,11 +54,6 @@ use rayon::prelude::*;
|
|||
|
||||
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(crate) passes_enabled: usize,
|
||||
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 {
|
||||
/// Load the shader preset at the given path into a filter chain.
|
||||
pub unsafe fn load_from_path(
|
||||
|
@ -219,29 +249,9 @@ impl FilterChainD3D12 {
|
|||
let shader_copy = preset.shaders.clone();
|
||||
let disable_cache = options.map_or(false, |o| o.disable_cache);
|
||||
|
||||
let (passes, semantics) = if !disable_cache {
|
||||
DXIL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
|
||||
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 (passes, semantics) =
|
||||
compile_passes_dxil(preset.shaders, &preset.textures, disable_cache)?;
|
||||
let (hlsl_passes, _) = compile_passes_hlsl(shader_copy, &preset.textures, disable_cache)?;
|
||||
|
||||
let samplers = SamplerSet::new(device)?;
|
||||
let mipmap_gen = D3D12MipmapGen::new(device, false)?;
|
||||
|
@ -368,7 +378,7 @@ impl FilterChainD3D12 {
|
|||
texture.filter_mode,
|
||||
texture.wrap_mode,
|
||||
texture.mipmap,
|
||||
gc
|
||||
gc,
|
||||
)?;
|
||||
luts.insert(index, texture);
|
||||
}
|
||||
|
@ -424,40 +434,50 @@ impl FilterChainD3D12 {
|
|||
let (sampler_work_heaps, _, sampler_heap_handle) =
|
||||
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(work_heaps)
|
||||
.zip(sampler_work_heaps)
|
||||
.enumerate()
|
||||
.map_init(
|
||||
|| {
|
||||
let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? };
|
||||
let validator: IDxcValidator =
|
||||
unsafe { DxcCreateInstance(&CLSID_DxcValidator)? };
|
||||
let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? };
|
||||
let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? };
|
||||
Ok::<_, FilterChainError>((validator, library, compiler))
|
||||
},
|
||||
|dxc, (index, ((((config, source, mut dxil),
|
||||
(_, _, mut hlsl)), mut texture_heap), mut sampler_heap))| {
|
||||
let Ok((validator, library, compiler)) = dxc else {
|
||||
return Err(FilterChainError::Direct3DOperationError("Could not initialize DXC for thread"));
|
||||
};
|
||||
|dxc,
|
||||
(
|
||||
index,
|
||||
(
|
||||
(((config, source, mut dxil), (_, _, mut hlsl)), mut texture_heap),
|
||||
mut sampler_heap,
|
||||
),
|
||||
)| {
|
||||
let Ok((validator, library, compiler)) = dxc else {
|
||||
return Err(FilterChainError::Direct3DOperationError(
|
||||
"Could not initialize DXC for thread",
|
||||
));
|
||||
};
|
||||
|
||||
let dxil_reflection = dxil.reflect(index, semantics)?;
|
||||
let dxil = dxil.compile(Some(
|
||||
librashader_reflect::back::dxil::ShaderModel::ShaderModel6_0,
|
||||
))?;
|
||||
let dxil_reflection = dxil.reflect(index, semantics)?;
|
||||
let dxil = dxil.compile(Some(
|
||||
librashader_reflect::back::dxil::ShaderModel::ShaderModel6_0,
|
||||
))?;
|
||||
|
||||
let render_format = if let Some(format) = config.get_format_override() {
|
||||
format
|
||||
} else if source.format != ImageFormat::Unknown {
|
||||
source.format
|
||||
} else {
|
||||
ImageFormat::R8G8B8A8Unorm
|
||||
}.into();
|
||||
let render_format = if let Some(format) = config.get_format_override() {
|
||||
format
|
||||
} else if source.format != ImageFormat::Unknown {
|
||||
source.format
|
||||
} else {
|
||||
ImageFormat::R8G8B8A8Unorm
|
||||
}
|
||||
.into();
|
||||
|
||||
|
||||
// incredibly cursed.
|
||||
let (reflection, graphics_pipeline) = if !force_hlsl &&
|
||||
// incredibly cursed.
|
||||
let (reflection, graphics_pipeline) = if !force_hlsl &&
|
||||
let Ok(graphics_pipeline) =
|
||||
D3D12GraphicsPipeline::new_from_dxil(
|
||||
device,
|
||||
|
@ -494,11 +514,11 @@ impl FilterChainD3D12 {
|
|||
|
||||
let uniform_storage = UniformStorage::new_with_storage(
|
||||
RawD3D12Buffer::new(D3D12Buffer::new(device, ubo_size)?)?,
|
||||
RawD3D12Buffer::new(D3D12Buffer::new(device, push_size)?)?
|
||||
);
|
||||
RawD3D12Buffer::new(D3D12Buffer::new(device, push_size)?)?,
|
||||
);
|
||||
|
||||
|
||||
let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset());
|
||||
let uniform_bindings =
|
||||
reflection.meta.create_binding_map(|param| param.offset());
|
||||
|
||||
let texture_heap = texture_heap.alloc_range()?;
|
||||
let sampler_heap = sampler_heap.alloc_range()?;
|
||||
|
@ -513,8 +533,9 @@ impl FilterChainD3D12 {
|
|||
sampler_heap,
|
||||
source,
|
||||
})
|
||||
|
||||
}).collect();
|
||||
},
|
||||
)
|
||||
.collect();
|
||||
|
||||
let filters: error::Result<Vec<_>> = filters.into_iter().collect();
|
||||
let filters = filters?;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeap};
|
||||
use crate::error;
|
||||
use crate::error::assume_d3d12_init;
|
||||
use crate::filter_chain::FrameResiduals;
|
||||
use crate::mipmap::MipmapGenContext;
|
||||
use crate::texture::InputTexture;
|
||||
use crate::util::{d3d12_get_closest_format, d3d12_resource_transition, d3d12_update_subresources};
|
||||
|
@ -22,7 +23,6 @@ use windows::Win32::Graphics::Direct3D12::{
|
|||
D3D12_TEX2D_SRV, D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
|
||||
};
|
||||
use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC;
|
||||
use crate::filter_chain::FrameResiduals;
|
||||
|
||||
pub struct LutTexture {
|
||||
resource: ID3D12Resource,
|
||||
|
|
|
@ -10,6 +10,7 @@ use windows::Win32::Graphics::Direct3D::Dxc::{
|
|||
DXC_CP_UTF8,
|
||||
};
|
||||
|
||||
use crate::filter_chain::FrameResiduals;
|
||||
use windows::Win32::Graphics::Direct3D12::{
|
||||
ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_FEATURE_DATA_FORMAT_SUPPORT,
|
||||
D3D12_FEATURE_FORMAT_SUPPORT, D3D12_MEMCPY_DEST, D3D12_PLACED_SUBRESOURCE_FOOTPRINT,
|
||||
|
@ -20,7 +21,6 @@ use windows::Win32::Graphics::Direct3D12::{
|
|||
D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
|
||||
};
|
||||
use windows::Win32::Graphics::Dxgi::Common::*;
|
||||
use crate::filter_chain::FrameResiduals;
|
||||
|
||||
/// wtf retroarch?
|
||||
const DXGI_FORMAT_EX_A4R4G4B4_UNORM: DXGI_FORMAT = DXGI_FORMAT(1000);
|
||||
|
@ -273,7 +273,7 @@ pub(crate) fn d3d12_update_subresources(
|
|||
&num_rows,
|
||||
&row_sizes_in_bytes,
|
||||
source,
|
||||
gc
|
||||
gc,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,11 +228,11 @@ unsafe extern "system" fn debug_log(
|
|||
}
|
||||
|
||||
pub mod d3d12_hello_triangle {
|
||||
use std::mem::ManuallyDrop;
|
||||
use super::*;
|
||||
use crate::hello_triangle::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeap};
|
||||
use librashader_common::{Size, Viewport};
|
||||
use librashader_runtime_d3d12::{D3D12InputImage, D3D12OutputView, FilterChainD3D12};
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::ops::Deref;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -571,7 +571,11 @@ pub mod d3d12_hello_triangle {
|
|||
// Record commands.
|
||||
unsafe {
|
||||
// TODO: workaround for https://github.com/microsoft/win32metadata/issues/1006
|
||||
command_list.ClearRenderTargetView(rtv_handle, &*[0.3, 0.4, 0.6, 1.0].as_ptr(), Some(&[]));
|
||||
command_list.ClearRenderTargetView(
|
||||
rtv_handle,
|
||||
&*[0.3, 0.4, 0.6, 1.0].as_ptr(),
|
||||
Some(&[]),
|
||||
);
|
||||
command_list.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
command_list.IASetVertexBuffers(0, Some(&[resources.vbv]));
|
||||
command_list.DrawInstanced(3, 1, 0, 0);
|
||||
|
|
|
@ -7,7 +7,7 @@ fn triangle_d3d12() {
|
|||
let sample = hello_triangle::d3d12_hello_triangle::Sample::new(
|
||||
//"../test/shaders_slang/crt/crt-lottes.slangp",
|
||||
// "../test/basic.slangp",
|
||||
"../test/shaders_slang/handheld/console-border/gbc-lcd-grid-v2.slangp",
|
||||
"../test/shaders_slang/handheld/console-border/gbc-lcd-grid-v2.slangp",
|
||||
// "../test/Mega_Bezel_Packs/Duimon-Mega-Bezel/Presets/Advanced/Nintendo_GBA_SP/GBA_SP-[ADV]-[LCD-GRID]-[Night].slangp",
|
||||
// "../test/slang-shaders/test/feedback.slangp",
|
||||
// "../test/slang-shaders/test/history.slangp",
|
||||
|
@ -17,6 +17,6 @@ fn triangle_d3d12() {
|
|||
use_warp_device: false,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
hello_triangle::main(sample).unwrap()
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::{error, GLImage};
|
|||
use gl::types::GLuint;
|
||||
use librashader_common::Viewport;
|
||||
|
||||
use librashader_presets::ShaderPreset;
|
||||
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
|
||||
use librashader_reflect::back::cross::GlslVersion;
|
||||
use librashader_reflect::back::targets::GLSL;
|
||||
use librashader_reflect::back::{CompileReflectShader, CompileShader};
|
||||
|
@ -98,6 +98,21 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
|||
}
|
||||
|
||||
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> {
|
||||
/// Load a filter chain from a pre-parsed `ShaderPreset`.
|
||||
|
@ -106,19 +121,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
|||
options: Option<&FilterChainOptionsGL>,
|
||||
) -> error::Result<Self> {
|
||||
let disable_cache = options.map_or(false, |o| o.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 (passes, semantics) = compile_passes(preset.shaders, &preset.textures, disable_cache)?;
|
||||
let version = options.map_or_else(gl_get_version, |o| gl_u16_to_version(o.glsl_version));
|
||||
|
||||
// initialize passes
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
//! See [`librashader::runtime::gl`](https://docs.rs/librashader/latest/librashader/runtime/gl/index.html) instead.
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
#![feature(strict_provenance)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
mod binding;
|
||||
mod filter_chain;
|
||||
|
|
|
@ -14,7 +14,7 @@ use ash::vk;
|
|||
use librashader_common::{ImageFormat, Size, Viewport};
|
||||
|
||||
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::{CompileReflectShader, CompileShader};
|
||||
use librashader_reflect::front::GlslangCompilation;
|
||||
|
@ -46,9 +46,6 @@ pub struct VulkanObjects {
|
|||
// pub(crate) memory_properties: vk::PhysicalDeviceMemoryProperties,
|
||||
}
|
||||
|
||||
type ShaderPassMeta =
|
||||
ShaderPassArtifact<impl CompileReflectShader<SPIRV, GlslangCompilation> + Send>;
|
||||
|
||||
/// A collection of handles needed to access the Vulkan instance.
|
||||
#[derive(Clone)]
|
||||
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 {
|
||||
/// Load the shader preset at the given path into a filter chain.
|
||||
pub unsafe fn load_from_path<V, E>(
|
||||
|
@ -307,18 +322,7 @@ impl FilterChainVulkan {
|
|||
FilterChainError: From<E>,
|
||||
{
|
||||
let disable_cache = options.map_or(false, |o| o.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 (passes, semantics) = compile_passes(preset.shaders, &preset.textures, disable_cache)?;
|
||||
|
||||
let device = vulkan.try_into().map_err(From::from)?;
|
||||
|
||||
|
|
|
@ -100,10 +100,10 @@ impl VulkanBuffer {
|
|||
|
||||
pub fn as_mut_slice(&mut self) -> error::Result<&mut [u8]> {
|
||||
let Some(allocation) = self.memory.as_mut() else {
|
||||
return Err(FilterChainError::AllocationDoesNotExist)
|
||||
return Err(FilterChainError::AllocationDoesNotExist);
|
||||
};
|
||||
let Some(allocation) = allocation.mapped_slice_mut() else {
|
||||
return Err(FilterChainError::AllocationDoesNotExist)
|
||||
return Err(FilterChainError::AllocationDoesNotExist);
|
||||
};
|
||||
Ok(allocation)
|
||||
}
|
||||
|
@ -147,11 +147,8 @@ impl RawVulkanBuffer {
|
|||
) -> error::Result<Self> {
|
||||
let buffer = ManuallyDrop::new(VulkanBuffer::new(device, allocator, usage, size)?);
|
||||
|
||||
let Some(ptr) = buffer.memory
|
||||
.as_ref()
|
||||
.map(|m| m.mapped_ptr())
|
||||
.flatten() else {
|
||||
return Err(FilterChainError::AllocationDoesNotExist)
|
||||
let Some(ptr) = buffer.memory.as_ref().map(|m| m.mapped_ptr()).flatten() else {
|
||||
return Err(FilterChainError::AllocationDoesNotExist);
|
||||
};
|
||||
|
||||
Ok(RawVulkanBuffer { buffer, ptr })
|
||||
|
|
Loading…
Add table
Reference in a new issue