rt(d3d12): replace let_chains with stable alternatives

This commit is contained in:
chyyran 2024-09-14 01:33:36 -04:00 committed by Ronny Chan
parent ab9ab6fe68
commit b432a1e02d
4 changed files with 41 additions and 30 deletions

View file

@ -535,35 +535,41 @@ impl FilterChainD3D12 {
.into(); .into();
// incredibly cursed. // incredibly cursed.
let (reflection, graphics_pipeline) = let (reflection, graphics_pipeline) = 'pipeline: {
if let Ok(graphics_pipeline) = D3D12GraphicsPipeline::new_from_dxil( 'dxil: {
device, if force_hlsl {
library, break 'dxil;
validator, }
&dxil,
root_signature,
render_format,
disable_cache,
) && !force_hlsl
{
(dxil_reflection, graphics_pipeline)
} else {
let hlsl_reflection = hlsl.reflect(index, semantics)?;
let hlsl = hlsl.compile(Some(
librashader_reflect::back::hlsl::HlslShaderModel::ShaderModel6_0,
))?;
let graphics_pipeline = D3D12GraphicsPipeline::new_from_hlsl( if let Ok(graphics_pipeline) = D3D12GraphicsPipeline::new_from_dxil(
device, device,
library, library,
compiler, validator,
&hlsl, &dxil,
root_signature, root_signature,
render_format, render_format,
disable_cache, disable_cache,
)?; ) {
(hlsl_reflection, graphics_pipeline) break 'pipeline (dxil_reflection, graphics_pipeline);
}; }
}
let hlsl_reflection = hlsl.reflect(index, semantics)?;
let hlsl = hlsl.compile(Some(
librashader_reflect::back::hlsl::HlslShaderModel::ShaderModel6_0,
))?;
let graphics_pipeline = D3D12GraphicsPipeline::new_from_hlsl(
device,
library,
compiler,
&hlsl,
root_signature,
render_format,
disable_cache,
)?;
(hlsl_reflection, graphics_pipeline)
};
// minimum size here has to be 1 byte. // minimum size here has to be 1 byte.
let ubo_size = reflection.ubo.as_ref().map_or(1, |ubo| ubo.size as usize); let ubo_size = reflection.ubo.as_ref().map_or(1, |ubo| ubo.size as usize);

View file

@ -160,14 +160,20 @@ impl FilterPass {
source, source,
); );
if let Some(ubo) = &self.reflection.ubo if self
&& ubo.size != 0 .reflection
.ubo
.as_ref()
.is_some_and(|ubo| ubo.size != 0)
{ {
self.uniform_storage.inner_ubo().bind_cbv(2, cmd); self.uniform_storage.inner_ubo().bind_cbv(2, cmd);
} }
if let Some(push) = &self.reflection.push_constant if self
&& push.size != 0 .reflection
.push_constant
.as_ref()
.is_some_and(|push| push.size != 0)
{ {
self.uniform_storage.inner_push().bind_cbv(3, cmd); self.uniform_storage.inner_push().bind_cbv(3, cmd);
} }

View file

@ -1,6 +1,5 @@
#![cfg(target_os = "windows")] #![cfg(target_os = "windows")]
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
#![feature(let_chains)]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
mod buffer; mod buffer;

View file

@ -5,14 +5,14 @@ use crate::hello_triangle::{DXSample, SampleCommandLine};
#[test] #[test]
fn triangle_d3d12() { fn triangle_d3d12() {
let sample = hello_triangle::d3d12_hello_triangle::Sample::new( let sample = hello_triangle::d3d12_hello_triangle::Sample::new(
// "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
// "../test/shaders_slang/crt/crt-lottes.slangp", // "../test/shaders_slang/crt/crt-lottes.slangp",
// "../test/basic.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/Mega_Bezel_Packs/Duimon-Mega-Bezel/Presets/Advanced/Nintendo_GBA_SP/GBA_SP-[ADV]-[LCD-GRID]-[Night].slangp",
// "../test/shaders_slang/test/feedback.slangp", // "../test/shaders_slang/test/feedback.slangp",
// "../test/shaders_slang/test/history.slangp", // "../test/shaders_slang/test/history.slangp",
"../test/shaders_slang/crt/crt-geom-deluxe.slangp", // "../test/shaders_slang/crt/crt-geom-deluxe.slangp",
// "../test/slang-shaders/vhs/VHSPro.slangp", // "../test/slang-shaders/vhs/VHSPro.slangp",
&SampleCommandLine { &SampleCommandLine {
use_warp_device: false, use_warp_device: false,