d3d12: make framebuffer

This commit is contained in:
chyyran 2023-01-31 01:25:45 -05:00 committed by Ronny Chan
parent 22599285d3
commit 17203692f0
7 changed files with 113 additions and 19 deletions

View file

@ -25,7 +25,6 @@ pub(crate) struct OwnedFramebuffer {
format: DXGI_FORMAT,
device: ID3D11Device,
context: ID3D11DeviceContext,
is_raw: bool,
max_mipmap: u32,
}
@ -56,7 +55,6 @@ impl OwnedFramebuffer {
format,
device: device.clone(),
context: context.clone(),
is_raw: false,
max_mipmap: if mipmap {
size.calculate_miplevels()
} else {
@ -74,10 +72,6 @@ impl OwnedFramebuffer {
source_size: &Size<u32>,
should_mipmap: bool,
) -> error::Result<Size<u32>> {
if self.is_raw {
return Ok(self.size);
}
let size = source_size.scale_viewport(scaling, *viewport_size);
if self.size != size

View file

@ -126,8 +126,8 @@ pub fn d3d_compile_shader(source: &[u8], entry: &[u8], version: &[u8]) -> error:
None,
)?;
// SAFETY: if D3DCompile succeeds then blob is Some
Ok(blob.unwrap())
assume_d3d11_init!(blob, "D3DCompile");
Ok(blob)
}
}

View file

@ -34,6 +34,11 @@ use crate::quad_render::DrawQuad;
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation>>;
pub struct FilterMutable {
pub(crate) passes_enabled: usize,
pub(crate) parameters: FxHashMap<String, f32>,
}
pub struct FilterChainD3D12 {
pub(crate) common: FilterCommon,
// pub(crate) passes: Vec<FilterPass>,
@ -41,24 +46,23 @@ pub struct FilterChainD3D12 {
// pub(crate) feedback_framebuffers: Box<[OwnedFramebuffer]>,
// pub(crate) history_framebuffers: VecDeque<OwnedFramebuffer>,
// pub(crate) draw_quad: DrawQuad,
pub(crate) filters: Vec<FilterPass>,
pub(crate) passes: Vec<FilterPass>,
}
pub(crate) struct FilterCommon {
pub(crate) d3d12: ID3D12Device,
// pub(crate) luts: FxHashMap<usize, LutTexture>,
pub samplers: SamplerSet,
// pub output_textures: Box<[Option<InputTexture>]>,
// pub feedback_textures: Box<[Option<InputTexture>]>,
// pub history_textures: Box<[Option<InputTexture>]>,
// pub config: FilterMutable,
pub config: FilterMutable,
// pub disable_mipmaps: bool,
lut_heap: D3D12DescriptorHeap<LutTextureHeap>,
luts: FxHashMap<usize, LutTexture>,
mipmap_gen: D3D12MipmapGen,
root_signature: D3D12RootSignature,
work_heap: D3D12DescriptorHeap<ResourceWorkHeap>,
draw_quad: DrawQuad,
pub luts: FxHashMap<usize, LutTexture>,
pub mipmap_gen: D3D12MipmapGen,
pub root_signature: D3D12RootSignature,
pub work_heap: D3D12DescriptorHeap<ResourceWorkHeap>,
pub draw_quad: DrawQuad,
}
impl FilterChainD3D12 {
@ -109,8 +113,16 @@ impl FilterChainD3D12 {
root_signature,
work_heap,
draw_quad,
config: FilterMutable {
passes_enabled: preset.shader_count as usize,
parameters: preset
.parameters
.into_iter()
.map(|param| (param.name, param.value))
.collect(),
},
filters
},
passes: filters
})
}

View file

@ -15,3 +15,4 @@ pub(crate) struct FilterPass {
pub(crate) push_cbuffer: Option<D3D12ConstantBuffer>,
pub(crate) ubo_cbuffer: Option<D3D12ConstantBuffer>,
}

View file

@ -0,0 +1,85 @@
use windows::Win32::Graphics::Direct3D12::{D3D12_CPU_PAGE_PROPERTY_UNKNOWN, D3D12_FEATURE_DATA_FORMAT_SUPPORT, D3D12_FORMAT_SUPPORT1_MIP, D3D12_FORMAT_SUPPORT1_RENDER_TARGET, D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE, D3D12_FORMAT_SUPPORT1_TEXTURE2D, D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE, D3D12_HEAP_FLAG_NONE, D3D12_HEAP_PROPERTIES, D3D12_HEAP_TYPE_DEFAULT, D3D12_MEMORY_POOL_UNKNOWN, D3D12_RESOURCE_DESC, D3D12_RESOURCE_DIMENSION_TEXTURE2D, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, ID3D12Device, ID3D12Resource};
use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_SAMPLE_DESC};
use librashader_common::{ImageFormat, Size};
use librashader_runtime::scaling::MipmapSize;
use crate::error;
use crate::error::assume_d3d12_init;
use crate::util::d3d12_get_closest_format;
#[derive(Debug, Clone)]
pub(crate) struct OwnedImage {
render: ID3D12Resource,
pub(crate) size: Size<u32>,
format: DXGI_FORMAT,
device: ID3D12Device,
max_mipmap: u16,
}
pub fn new(
device: &ID3D12Device,
size: Size<u32>,
format: ImageFormat,
mipmap: bool,
) -> error::Result<OwnedImage> {
unsafe {
let miplevels = source.size.calculate_miplevels() as u16;
let mut desc = D3D12_RESOURCE_DESC {
Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
Alignment: 0,
Width: size.width as u64,
Height: size.height,
DepthOrArraySize: 1,
MipLevels: if mipmap { miplevels } else { 1 },
Format: format.into(),
SampleDesc: DXGI_SAMPLE_DESC {
Count: 1,
Quality: 0,
},
Layout: Default::default(),
Flags: Default::default(),
};
let mut format_support = D3D12_FEATURE_DATA_FORMAT_SUPPORT {
Format: desc.Format,
Support1: D3D12_FORMAT_SUPPORT1_TEXTURE2D
| D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE
| D3D12_FORMAT_SUPPORT1_RENDER_TARGET,
..Default::default()
};
if mipmap {
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
format_support.Support1 |= D3D12_FORMAT_SUPPORT1_MIP;
format_support.Support2 |= D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE;
}
desc.Format = d3d12_get_closest_format(device, desc.Format, format_support);
let mut resource: Option<ID3D12Resource> = None;
unsafe {
device.CreateCommittedResource(
&D3D12_HEAP_PROPERTIES {
Type: D3D12_HEAP_TYPE_DEFAULT,
CPUPageProperty: D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
MemoryPoolPreference: D3D12_MEMORY_POOL_UNKNOWN,
CreationNodeMask: 1,
VisibleNodeMask: 1,
},
D3D12_HEAP_FLAG_NONE,
&desc,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
None,
&mut resource,
)?;
}
assume_d3d12_init!(resource, "CreateCommittedResource");
Ok(OwnedImage {
render: resource,
size,
format: desc.Format,
device: device.clone(),
max_mipmap: miplevels,
})
}
}

View file

@ -13,6 +13,7 @@ mod filter_pass;
mod quad_render;
mod graphics_pipeline;
mod buffer;
mod framebuffer;
#[cfg(test)]
mod tests {

View file

@ -138,7 +138,8 @@ pub fn d3d_compile_shader(source: &[u8], entry: &[u8], version: &[u8]) -> error:
None,
)?;
Ok(blob.unwrap())
assume_d3d12_init!(blob, "D3DCompile");
Ok(blob)
}
}