dx12: cleanup and micro-opts
This commit is contained in:
parent
621d1da3c2
commit
f077f86bad
48
Cargo.lock
generated
48
Cargo.lock
generated
|
@ -101,6 +101,18 @@ version = "1.3.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitvec"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
|
||||
dependencies = [
|
||||
"funty",
|
||||
"radium",
|
||||
"tap",
|
||||
"wyz",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block"
|
||||
version = "0.1.6"
|
||||
|
@ -554,6 +566,12 @@ dependencies = [
|
|||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "funty"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
||||
|
||||
[[package]]
|
||||
name = "fxhash"
|
||||
version = "0.2.1"
|
||||
|
@ -885,7 +903,7 @@ name = "librashader-runtime-d3d12"
|
|||
version = "0.1.0-beta.8"
|
||||
dependencies = [
|
||||
"array-init",
|
||||
"bit-set",
|
||||
"bitvec",
|
||||
"bytemuck",
|
||||
"gfx-maths",
|
||||
"librashader-common",
|
||||
|
@ -897,6 +915,7 @@ dependencies = [
|
|||
"rayon",
|
||||
"rustc-hash",
|
||||
"thiserror",
|
||||
"widestring",
|
||||
"windows",
|
||||
]
|
||||
|
||||
|
@ -1397,6 +1416,12 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "radium"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
|
||||
|
||||
[[package]]
|
||||
name = "raw-window-handle"
|
||||
version = "0.4.3"
|
||||
|
@ -1678,6 +1703,12 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tap"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
|
@ -1935,6 +1966,12 @@ dependencies = [
|
|||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "widestring"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
@ -2132,6 +2169,15 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wyz"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
|
||||
dependencies = [
|
||||
"tap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x11-dl"
|
||||
version = "2.21.0"
|
||||
|
|
|
@ -23,7 +23,8 @@ spirv_cross = { package = "librashader-spirv-cross", version = "0.23" }
|
|||
rustc-hash = "1.1.0"
|
||||
bytemuck = { version = "1.12.3", features = ["derive"] }
|
||||
array-init = "2.1.0"
|
||||
bit-set = "0.5.3"
|
||||
bitvec = "1.0.1"
|
||||
widestring = "1.0.2"
|
||||
|
||||
rayon = "1.6.1"
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ use std::cell::RefCell;
|
|||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use bitvec::{bits, bitvec};
|
||||
use bitvec::boxed::BitBox;
|
||||
|
||||
use crate::error::FilterChainError;
|
||||
use windows::Win32::Graphics::Direct3D12::{
|
||||
|
@ -154,13 +156,7 @@ struct D3D12DescriptorHeapInner {
|
|||
handle_size: usize,
|
||||
start: usize,
|
||||
num_descriptors: usize,
|
||||
// Bit flag representation of available handles in the heap.
|
||||
//
|
||||
// 0 - Occupied
|
||||
// 1 - free
|
||||
|
||||
// todo: actually use a bitset here.
|
||||
map: Box<[bool]>,
|
||||
map: BitBox,
|
||||
}
|
||||
|
||||
pub struct D3D12DescriptorHeap<T>(Rc<RefCell<D3D12DescriptorHeapInner>>, PhantomData<T>);
|
||||
|
@ -197,7 +193,7 @@ impl<T> D3D12DescriptorHeap<T> {
|
|||
handle_size: device.GetDescriptorHandleIncrementSize(desc.Type) as usize,
|
||||
start: 0,
|
||||
num_descriptors: desc.NumDescriptors as usize,
|
||||
map: vec![false; desc.NumDescriptors as usize].into_boxed_slice(),
|
||||
map: bitvec![0; desc.NumDescriptors as usize].into_boxed_bitslice()
|
||||
})),
|
||||
PhantomData::default(),
|
||||
))
|
||||
|
@ -257,7 +253,7 @@ impl<T> D3D12DescriptorHeap<T> {
|
|||
handle_size: inner.handle_size,
|
||||
start: 0,
|
||||
num_descriptors: size,
|
||||
map: vec![false; size].into_boxed_slice(),
|
||||
map: bitvec![0; size].into_boxed_bitslice()
|
||||
});
|
||||
|
||||
start += size;
|
||||
|
@ -280,7 +276,7 @@ impl<T> D3D12DescriptorHeap<T> {
|
|||
let mut inner = self.0.borrow_mut();
|
||||
for i in inner.start..inner.num_descriptors {
|
||||
if !inner.map[i] {
|
||||
inner.map[i] = true;
|
||||
inner.map.set(i, true);
|
||||
handle.ptr = inner.cpu_start.ptr + (i * inner.handle_size);
|
||||
inner.start = i + 1;
|
||||
|
||||
|
@ -314,7 +310,7 @@ impl<T> D3D12DescriptorHeap<T> {
|
|||
impl<T> Drop for D3D12DescriptorHeapSlotInner<T> {
|
||||
fn drop(&mut self) {
|
||||
let mut inner = self.heap.borrow_mut();
|
||||
inner.map[self.slot] = false;
|
||||
inner.map.set(self.slot, false);
|
||||
if inner.start > self.slot {
|
||||
inner.start = self.slot
|
||||
}
|
||||
|
|
|
@ -25,15 +25,12 @@ use librashader_reflect::reflect::ReflectShader;
|
|||
use librashader_runtime::binding::{BindingUtil, TextureInput};
|
||||
use librashader_runtime::image::{Image, UVDirection};
|
||||
use librashader_runtime::quad::{QuadType, DEFAULT_MVP};
|
||||
use librashader_runtime::scaling::MipmapSize;
|
||||
use librashader_runtime::uniforms::UniformStorage;
|
||||
use rustc_hash::FxHashMap;
|
||||
use spirv_cross::hlsl::ShaderModel;
|
||||
use std::collections::VecDeque;
|
||||
use std::error::Error;
|
||||
use std::path::Path;
|
||||
use windows::core::Interface;
|
||||
use windows::w;
|
||||
use windows::Win32::Foundation::CloseHandle;
|
||||
use windows::Win32::Graphics::Direct3D::Dxc::{
|
||||
CLSID_DxcCompiler, CLSID_DxcLibrary, CLSID_DxcValidator, DxcCreateInstance, IDxcCompiler,
|
||||
|
@ -273,8 +270,6 @@ impl FilterChainD3D12 {
|
|||
NodeMask: 0,
|
||||
})?;
|
||||
|
||||
queue.SetName(w!("LutQueue"))?;
|
||||
|
||||
let fence_event = unsafe { CreateEventA(None, false, false, None)? };
|
||||
let fence: ID3D12Fence = device.CreateFence(0, D3D12_FENCE_FLAG_NONE)?;
|
||||
let mut residuals = Vec::new();
|
||||
|
|
|
@ -39,7 +39,6 @@ impl LutTexture {
|
|||
wrap_mode: WrapMode,
|
||||
mipmap: bool,
|
||||
) -> error::Result<(LutTexture, ID3D12Resource)> {
|
||||
// todo: d3d12:800
|
||||
let miplevels = source.size.calculate_miplevels() as u16;
|
||||
let mut desc = D3D12_RESOURCE_DESC {
|
||||
Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::error;
|
|||
use bytemuck::{offset_of, Pod, Zeroable};
|
||||
use librashader_runtime::quad::QuadType;
|
||||
use windows::core::PCSTR;
|
||||
use windows::w;
|
||||
use windows::Win32::Graphics::Direct3D::D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
|
||||
use windows::Win32::Graphics::Direct3D12::{
|
||||
ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource,
|
||||
|
@ -66,9 +65,6 @@ impl DrawQuad {
|
|||
};
|
||||
|
||||
let buffer = buffer.into_raw();
|
||||
unsafe {
|
||||
buffer.SetName(w!("drawquad"))?;
|
||||
}
|
||||
Ok(DrawQuad { buffer, view })
|
||||
}
|
||||
|
||||
|
|
|
@ -4,14 +4,13 @@ use librashader_reflect::reflect::semantics::BindingStage;
|
|||
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::u64;
|
||||
use widestring::u16cstr;
|
||||
use windows::core::{Interface, PCSTR, PCWSTR};
|
||||
use windows::Win32::Graphics::Direct3D::Dxc::{
|
||||
DxcValidatorFlags_InPlaceEdit, IDxcBlob, IDxcBlobUtf8, IDxcCompiler, IDxcUtils, IDxcValidator,
|
||||
DXC_CP, DXC_CP_UTF8,
|
||||
};
|
||||
use windows::Win32::Graphics::Direct3D::Fxc::{
|
||||
D3DCompile, D3DCOMPILE_DEBUG, D3DCOMPILE_SKIP_OPTIMIZATION,
|
||||
};
|
||||
use windows::Win32::Graphics::Direct3D::Fxc::{D3DCompile, D3DCOMPILE_DEBUG, D3DCOMPILE_OPTIMIZATION_LEVEL3, D3DCOMPILE_SKIP_OPTIMIZATION};
|
||||
use windows::Win32::Graphics::Direct3D::ID3DBlob;
|
||||
use windows::Win32::Graphics::Direct3D12::{
|
||||
ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_FEATURE_DATA_FORMAT_SUPPORT,
|
||||
|
@ -132,7 +131,6 @@ pub fn d3d12_get_closest_format(
|
|||
}
|
||||
|
||||
pub fn fxc_compile_shader(source: &[u8], entry: &[u8], version: &[u8]) -> error::Result<ID3DBlob> {
|
||||
// todo: compile with dxc
|
||||
unsafe {
|
||||
let mut blob = None;
|
||||
D3DCompile(
|
||||
|
@ -143,12 +141,11 @@ pub fn fxc_compile_shader(source: &[u8], entry: &[u8], version: &[u8]) -> error:
|
|||
None,
|
||||
PCSTR(entry.as_ptr()),
|
||||
PCSTR(version.as_ptr()),
|
||||
D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,
|
||||
// if cfg!(feature = "debug-shader") {
|
||||
// D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION
|
||||
// } else {
|
||||
// D3DCOMPILE_OPTIMIZATION_LEVEL3
|
||||
// },
|
||||
if cfg!(feature = "debug-shader") {
|
||||
D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION
|
||||
} else {
|
||||
D3DCOMPILE_OPTIMIZATION_LEVEL3
|
||||
},
|
||||
0,
|
||||
&mut blob,
|
||||
None,
|
||||
|
@ -165,9 +162,6 @@ pub fn dxc_compile_shader(
|
|||
source: &String,
|
||||
profile: BindingStage,
|
||||
) -> error::Result<IDxcBlob> {
|
||||
// todo: compile with dxc
|
||||
// let mut source = source.to_vec();
|
||||
|
||||
let include = unsafe { library.CreateDefaultIncludeHandler()? };
|
||||
|
||||
let blob = unsafe {
|
||||
|
@ -179,17 +173,17 @@ pub fn dxc_compile_shader(
|
|||
};
|
||||
|
||||
let profile = if profile == BindingStage::FRAGMENT {
|
||||
windows::w!("ps_6_0")
|
||||
u16cstr!("ps_6_0")
|
||||
} else {
|
||||
windows::w!("vs_6_0")
|
||||
u16cstr!("vs_6_0")
|
||||
};
|
||||
|
||||
unsafe {
|
||||
let result = compiler.Compile(
|
||||
&blob,
|
||||
PCWSTR::null(),
|
||||
windows::w!("main"),
|
||||
profile,
|
||||
PCWSTR(u16cstr!("main").as_ptr()),
|
||||
PCWSTR(profile.as_ptr()),
|
||||
None,
|
||||
&[],
|
||||
&include,
|
||||
|
@ -205,9 +199,6 @@ pub fn dxc_validate_shader(
|
|||
validator: &IDxcValidator,
|
||||
source: &[u8],
|
||||
) -> error::Result<IDxcBlob> {
|
||||
// todo: compile with dxc
|
||||
// let mut source = source.to_vec();
|
||||
|
||||
let blob =
|
||||
unsafe { library.CreateBlob(source.as_ptr().cast(), source.len() as u32, DXC_CP(0))? };
|
||||
|
||||
|
|
Loading…
Reference in a new issue